Constants not loaded by compiler

后端 未结 5 1294
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 19:49

I started studying POSIX timers, so I started also doing some exercises, but I immediately had some problems with the compiler. When compiling this code, I get some strange

5条回答
  •  一整个雨季
    2021-01-04 20:31

    The other answers suggest _POSIX_C_SOURCE as the enabling macro. That certainly works, but it doesn't necessarily enable everything that is in the Single Unix Specification (SUS). For that, you should set _XOPEN_SOURCE, which also automatically sets _POSIX_C_SOURCE. I have a header I call "posixver.h" which contains:

    /*
    ** Include this file before including system headers.  By default, with
    ** C99 support from the compiler, it requests POSIX 2001 support.  With
    ** C89 support only, it requests POSIX 1997 support.  Override the
    ** default behaviour by setting either _XOPEN_SOURCE or _POSIX_C_SOURCE.
    */
    
    /* _XOPEN_SOURCE 700 is loosely equivalent to _POSIX_C_SOURCE 200809L */
    /* _XOPEN_SOURCE 600 is loosely equivalent to _POSIX_C_SOURCE 200112L */
    /* _XOPEN_SOURCE 500 is loosely equivalent to _POSIX_C_SOURCE 199506L */
    
    #if !defined(_XOPEN_SOURCE) && !defined(_POSIX_C_SOURCE)
    #if __STDC_VERSION__ >= 199901L
    #define _XOPEN_SOURCE 600   /* SUS v3, POSIX 1003.1 2004 (POSIX 2001 + Corrigenda) */
    #else
    #define _XOPEN_SOURCE 500   /* SUS v2, POSIX 1003.1 1997 */
    #endif /* __STDC_VERSION__ */
    #endif /* !_XOPEN_SOURCE && !_POSIX_C_SOURCE */
    

    It is tuned for the systems I work with which don't all recognize the 700 value. If you are working on a relatively modern Linux, I believe you can use 700. It's in a header so that I only have to change one file when I want to alter the rules.

提交回复
热议问题