Precedence of -D MACRO and #define MACRO

后端 未结 5 621
情歌与酒
情歌与酒 2021-01-11 14:24

If I have a C file foo.c and while I have given -DMACRO=1 as command line option for compilation. However, if within the header file also I hav

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-11 15:18

    I'm making an assumption of what you're doing, but if you'd like to supply from the command-line a non-default value for that macro, try this for the macro definition:

    #ifndef MACRO
    #define MACRO 2
    #endif
    

    That way if the MACRO has already been defined (via command-line parameter) it will neither be redefined nor result in an error.

提交回复
热议问题