C C++

GNU C compiler에 -ansi 옵션을 주었을때 발생하는 효과

_침묵_ 2006. 11. 10. 06:26

출처 :http://superkkt.com/177

 

아래 내용은 /usr/include/features.h에서 발췌한 내용이다. 볼드로 처리된 부분이 중요함!!
-ansi를 사용하면 __STRICT_ANSI__가 작동하기 때문에 POSIX 확장으로 처리된 부분들이 컴파일시 포함되지 않아서 많은 에러와 직면하게 된다. :-(

/* These are defined by the user (or the compiler)
  to specify the desired environment:

  __STRICT_ANSI__  ISO Standard C.
  _ISOC99_SOURCE   Extensions to ISO C89 from ISO C99.
  _POSIX_SOURCE    IEEE Std 1003.1.
  _POSIX_C_SOURCE  If ==1, like _POSIX_SOURCE; if >=2 add IEEE Std 1003.2;
           if >=199309L, add IEEE Std 1003.1b-1993;
           if >=199506L, add IEEE Std 1003.1c-1995;
           if >=200112L, all of IEEE 1003.1-2004
  _XOPEN_SOURCE    Includes POSIX and XPG things.  Set to 500 if
           Single Unix conformance is wanted, to 600 for the
           upcoming sixth revision.
  _XOPEN_SOURCE_EXTENDED XPG things and X/Open Unix extensions.
  _LARGEFILE_SOURCE    Some more functions for correct standard I/O.
  _LARGEFILE64_SOURCE  Additional functionality from LFS for large files.
  _FILE_OFFSET_BITS=N  Select default filesystem interface.
  _BSD_SOURCE      ISO C, POSIX, and 4.3BSD things.
  _SVID_SOURCE     ISO C, POSIX, and SVID things.
  _GNU_SOURCE      All of the above, plus GNU extensions.
  _REENTRANT       Select additionally reentrant object.
  _THREAD_SAFE     Same as _REENTRANT, often used by other systems.
  _FORTIFY_SOURCE  If set to numeric value > 0 additional security
           measures are defined, according to level.

 The `-ansi' switch to the GNU C compiler defines __STRICT_ANSI__.
  If none of these are defined, the default is to have _SVID_SOURCE,
  _BSD_SOURCE, and _POSIX_SOURCE set to one and _POSIX_C_SOURCE set to
  199506L.  If more than one of these are defined, they accumulate.
  For example __STRICT_ANSI__, _POSIX_SOURCE and _POSIX_C_SOURCE
  together give you ISO C, 1003.1, and 1003.2, but nothing else.

  These are defined by this file and are used by the
  header files to decide what to declare or define:

  __USE_ISOC99     Define ISO C99 things.
  __USE_POSIX      Define IEEE Std 1003.1 things.
  __USE_POSIX2     Define IEEE Std 1003.2 things.
  __USE_POSIX199309    Define IEEE Std 1003.1, and .1b things.
  __USE_POSIX199506    Define IEEE Std 1003.1, .1b, .1c and .1i things.
  __USE_XOPEN      Define XPG things.
  __USE_XOPEN_EXTENDED Define X/Open Unix things.
  __USE_UNIX98     Define Single Unix V2 things.
  __USE_XOPEN2K        Define XPG6 things.
  __USE_LARGEFILE  Define correct standard I/O things.
  __USE_LARGEFILE64    Define LFS things with separate names.
  __USE_FILE_OFFSET64  Define 64bit interface as default.
  __USE_BSD        Define 4.3BSD things.
  __USE_SVID       Define SVID things.
  __USE_MISC       Define things common to BSD and System V Unix.
  __USE_GNU        Define GNU extensions.
  __USE_REENTRANT  Define reentrant/thread-safe *_r functions.
  __USE_FORTIFY_LEVEL  Additional security measures used, according to level.
  __FAVOR_BSD      Favor 4.3BSD things in cases of conflict.

  The macros `__GNU_LIBRARY__', `__GLIBC__', and `__GLIBC_MINOR__' are
  defined by this file unconditionally.  `__GNU_LIBRARY__' is provided
  only for compatibility.  All new code should use the other symbols
  to test for features.

  All macros listed above as possibly being defined by this file are
  explicitly undefined if they are not explicitly defined.
  Feature-test macros that are not defined by the user or compiler
  but are implied by the other feature-test macros defined (or by the
  lack of any definitions) are defined by the file.  */