Thread: Simle macro

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    58

    Simle macro

    Hi All;

    Looking for hepl with a simple macro or even is it possible. I can do macro functions but this is annoying me.

    Basically i have a #define called START. I want start to have two values, lets say 4 and 8.

    Then i want to check if the input value is equal to start.

    Would of thought this would work:
    #define START(x) ((x) == 4 ? (x) == 8)

    Thanks

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    58
    Actually got it there now, what i have is:
    #define START(x) (x) == 4| (x) == 8

    If any better way let us know
    Thanks

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    ALWAYS parenthesize all arguments and the whole macro expression

    Code:
    #define START(x) ((x) == 4 | (x) == 8)
    This is binary OR; I think you need logical OR (though the result is the same for this expression)
    Code:
    #define START(x) ((x) == 4 || (x) == 8)
    But I suggest a different alternative: make it a function rather than a macro
    Code:
    int isStart(int x) { return (x == 4 || x == 8); }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. macro use.
    By gourav87 in forum C Programming
    Replies: 8
    Last Post: 02-15-2012, 11:04 AM
  2. help with macro
    By dudeomanodude in forum C++ Programming
    Replies: 4
    Last Post: 02-12-2008, 01:55 PM
  3. L macro
    By George2 in forum C Programming
    Replies: 1
    Last Post: 08-20-2007, 09:24 AM
  4. RGB macro
    By Magos in forum Game Programming
    Replies: 1
    Last Post: 04-10-2006, 03:57 PM
  5. macro
    By sballew in forum C Programming
    Replies: 2
    Last Post: 10-10-2001, 07:51 PM