#define IDENTIFIER without a token

前端 未结 4 531
长发绾君心
长发绾君心 2020-12-06 00:05

What does the following statement mean:

#define FAHAD

I am familiar with the statements like:

#define FAHAD 1
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 00:52

    it means that FAHAD is defined, you can later check if it's defined or not with:

    #ifdef FAHAD
      //do something
    #else
      //something else
    #endif
    

    Or:

    #ifndef FAHAD //if not defined
    //do something
    #endif
    

    A real life example use is to check if a function or a header is available for your platform, usually a build system will define macros to indicate that some functions or headers exist before actually compiling, for example this checks if signal.h is available:

    #ifdef HAVE_SIGNAL_H
    #   include 
    #endif/*HAVE_SIGNAL_H*/
    

    This checks if some function is available

    #ifdef HAVE_SOME_FUNCTION
    //use this function
    #else
    //else use another one
    #endif
    

提交回复
热议问题