Search code examples
c++precompile

What does following precompilation mean?


Confronted with a C++ project recently and frequently see following precompilation code:

#ifdef _WIN32
#define __attribute__(x)
#endif

So in a general way what it is used for ?


Solution

  • __attribute__ is a special keyword supported e.g. by gcc, to specify things like alignment.

    The given statement adds an empty #define for __attribute__ so that it is deleted by the pre processor when _WIN32 is defined. This is e.g. required, if the compiler does not support __attribute__.

    EDIT

    A macro could have e.g. the following form:

    #define DOUBLE(x) (x*2)
    

    So if you would write DOUBLE(4) in your source it would be expanded/replace by the preprocessor to (4*2) before it is passed to the compiler. If omit the part to which it should be expanded, it would be expanded to an empty string.