This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Command Line Macro Definition



Hi,

Can I define the following macro on the command line using --define?

    #define UNUSED_PARAMETER(x)         (void) (x)

And if so how?

Thanks,

Matt

  • Try this; make sure you keep all of the parentheses inside quotes:

    -D"UNUSED_PARAMETER(x)=(void)(x)"
    
    
  • Archaeologist said:
    Try this; make sure you keep all of the parentheses inside quotes:
    -D"UNUSED_PARAMETER(x)=(void)(x)"
    
    

    Thanks, that's it!

    I thought I had tried this already but what I tried was:

      -define="UNUSED_PARAMETER(x) = (void)(x)"

    (there are spaces around the '=') and that doesn't work!

    Thanks,

    Matt

  • Some background comments for anyone else who finds this discussion: At a basic level, the format of the option is -D NAME or -D NAME=VALUE with no spaces around the equals sign, and you want to use UNUSED_PARAMETER(x) as NAME and (void)(x) as VALUE.  With those values for NAME and VALUE, though, the command shell you're using will have issues with the parenthesis, so you need to quote your NAME and VALUE to protect (or escape) them from the command shell: -D"UNUSED_PARAMETER(x)"="(void)(x)" or -D"UNUSED_PARAMETER(x)=(void)(x)", and you correctly figured that out.  Whether you quote the whole thing as one or quote the separate NAME and VALUE parts, the result is the same: your command shell takes the text within the quotes literally and does not try to interpret it as command shell syntax.

    But then to satisfy the format of the command-line option, you cannot have any spaces on either side of the equals sign, or else it appears to the option parser that you have only specified -DUNUSED_PARAMETER(x) (giving the macro a NULL value) and there are some characters following it (the = and then the (void)(x) ) which lead to an error.  Once you removed the extra spaces around your equals sign, the text became the single NAME=VALUE argument format the -D option was expecting.  Note that you can have spaces (or even an equals sign) within the VALUE itself, as long as it's quoted properly for the command shell and the spaces are not around the equals sign.  (Example: -DBIGMACRO="MACRO1 && MACRO2==2" )

     

  • Good explanation, thanks!