Thread: Macro arguments

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    1

    Macro arguments

    Hi
    Is it possible to check the value of a macro argument?

    for example here is the start of my macro

    #define fred messageOK
    #define MyMacro(scope) <rest of macro>

    I want to be able to check if 'scope' is equal to 'fred'

    Thanks for any help

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,110
    How would you do the comparison with numerical variables or constants, or string variable or constants?

    #define macros are translated by the preprocessor. Any comparisons would be done in normal C code after that translation.

    For example:
    Code:
    #define X 10
    #define Y 5
    
    // ...
    
    if(X > Y)
    {
    // ...
    }
    would be seen by the compiler as:
    Code:
    // ...
    
    if(10 > 5)
    {
    // ...
    }
    String comparisons would need to be done by string functions such as strcmp(), strncmp(), etc...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. macro
    By cable in forum C Programming
    Replies: 6
    Last Post: 09-17-2011, 06:54 AM
  2. variable number of arguments for a function or a macro
    By mynickmynick in forum C Programming
    Replies: 5
    Last Post: 05-19-2010, 11:35 AM
  3. passing arguments using "Command Line Arguments"
    By Madshan in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2006, 03:46 PM
  4. RGB macro
    By Magos in forum Game Programming
    Replies: 1
    Last Post: 04-10-2006, 03:57 PM
  5. Replies: 2
    Last Post: 05-05-2002, 09:27 AM

Tags for this Thread