About predefined macros for standard C languages

Source: Internet
Author: User

Standard C-language preprocessing requires defining some object macros, with the name of each of the predefined macros beginning and ending with one or two underscore characters that cannot be undefined (#undef) or redefined by programmers. The following predefined macro table, I copied it down.
__line__ the line number of the current program line, expressed as a decimal integer constant
__file__ the current source file name, which represents the string type constant
__DATE__ converts a calendar date, expressed as a string constant in the form of MMM DD yyyy, which is produced by Asctime.
The time of the __time__ conversion, which represents a string constant in the form of "Hh:mm:ss", is generated asctime. (a function that Asctime seems to refer to)
__stdc__ editor implements time-bit decimal integer constants for ISO compatibility
__stdc_version__ How to implement composite C89 full 1, the value of this macro is 19940SL, if the implementation conforms to C99, the value of this macro is 199901L; otherwise the value is undefined
__STDC_EOBTED__ (C99) Implementation is 1 for the host and implemented as a standalone implementation of 0
__stdc_iec_559__ (C99) floating point number to achieve composite IBC 60559 standard when defined as 1, no value is undefined
__STDC_IEC_559_COMPLEX__ (C99) complex operation to achieve composite IBC 60559 standard when defined as 1, no value is undefined
__STDC_ISO_10646__ (C99) is defined as a long integer constant, YYYYMML represents the wchar_t value of the composite ISO 10646 standard and its specified revision supplement, otherwise the value is undefined

Implementations also often define other macros for passing environment information, such as the type of computer on which the program compiles. The specific macro values are defined by the implementation, but UNIX implementations are accustomed to predefined UNIX. Unlike built-in macros, these macros can be de-defined. The standard C language requires a specific implementation of the macro name to start with an underscore, plus uppercase letters or another underscore (Unix macros do not meet this requirement).

Practical use, Example: Predefined macros can be used in magic error messages:
if (n|=m) fprintf (stderr, "Internal error;line%d,file 5s\n", __line__,__file__);

Other implementation-defined macros can separate the host or specific target code. For example, Microsoft Visual C + + defines __WIN32 as 1:
#ifdef __WIN32
/*code for Win32 environment*/
#endif

__STDC__ and __STDC_VERSION__ macros can write programs that implement beloved content with standard C and non-standard C:
#ifdef __stdc__
/*some version of Standard c*/
#if defined (__stdc__version__) &&__stdc_version__>=199901l
/* C99 */
#elif defined (__stdc_version__) &&__stdc_version__>=199409l
/*c89 and Amendment 1 */
#else
/* C89 but not amendment 1*/
#endif
#else/* __stdc__not defined */
/*not Standard c*/
endif

reference:http://blog.csdn.net/hrbeuwhw/article/details/7484432

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.