Thread: Preprocessor ?

  1. #1
    Registered User
    Join Date
    Mar 2013

    Question Preprocessor ?

    I recently came across a #define in a C program I was looking at and I was not quite sure why they surrounded the defined value with () as seen below. To me they look both essentially the same.

    #define NUM_VIC_VECT_PRIORITY_REGS  (32)
    I am just curious why they did not do

    instead of

    #define NUM_VIC_VECT_PRIORITY_REGS  (32)
    Does it make any difference or is there some special meaning here?

  2. #2
    Registered User
    Join Date
    May 2009
    It is a habit I did for a while; that is needed for compound values like (3+1).
    I often have two MACROs where the second one is just 1 more.

    #define MAX_STRING_SIZE 31
    I have never had something weird happen without () for non compound values. I am not an expect; so, it might be possible.

    But, I have had issues with compound values without ().

    Tim S.
    Last edited by stahta01; 03-09-2013 at 05:42 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jun 2005
    Quote Originally Posted by ZK57 View Post
    Does it make any difference or is there some special meaning here?
    The main difference is that the form with brackets prevents the macro being concatenated by other macros.

    The circumstances in which you would want other macros to concatenate macros of this form are rare, and the brackets prevents that occurring by accident.

    Personally, rather than preventing concatenation of macros, I think it is better to minimise ANY use of macro trickery. If you're not using excessive macro trickery, no need for additional macro trickery to prevent accidents.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Preprocessor help
    By royen in forum C++ Programming
    Replies: 3
    Last Post: 05-14-2009, 10:56 AM
  2. preprocessor help
    By brunogon in forum C Programming
    Replies: 13
    Last Post: 06-16-2008, 11:14 AM
  3. preprocessor!!
    By nishu1988 in forum C++ Programming
    Replies: 6
    Last Post: 07-24-2007, 11:31 PM
  4. Preprocessor
    By manutd in forum C++ Programming
    Replies: 5
    Last Post: 11-29-2006, 04:37 PM
  5. C preprocessor
    By Unregisterd in forum C Programming
    Replies: 1
    Last Post: 09-04-2001, 12:17 PM