Jump to content
Sign in to follow this  
blowback

weird behaviour with parentheses () in #ifdefs

Recommended Posts

Wotchamates,

 

If I define a macro like this:

 

#define FOO (porta,7)

 

then a statement like this:

 

set_bit(FOO);

 

will generate an error "variable or number expected". Similarly "set_bit( FOO );" and "set_bit((FOO));" and any variations thereof.

 

Bizarrely tho, "set_bit FOO;" is accepted!

 

This is a little broken, no?

Share this post


Link to post
Share on other sites
Guest Dave

Blowback,

 

Think about what this will macro expand to

set_bit( (porta,7) );

 

To many brackets here for a correct argument list!

 

drop the brackets in the macro

#define FOO porta,7

 

Then you get:

set_bit( porta,7 );

 

Just what you want ::P:

 

Regards

Dave

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...