predefined macros

Predefined Macros in C

In C programming, predefined macros are special identifiers that are defined by the compiler. They provide information about the environment, the compiler, and the operating system. Here are some of the commonly used predefined macros in C:

  1. __DATE__: This macro expands to a string constant that represents the date on which the compilation process began. It has the format "Mmm dd yyyy" (e.g., "Dec 04 2023").
  2. Source:
  3. __TIME__: Similar to __DATE__, this macro expands to a string constant that represents the time at which the compilation process began. It has the format "hh:mm:ss" (e.g., "03:55:27").
  4. Source:
  5. __FILE__: This macro expands to the name of the current source file, as a string constant.
  6. Source:
  7. __LINE__: This macro expands to the current line number in the source file as an integer constant.
  8. Source:
  9. __STDC__: This macro is defined to the value 1 when the compiler complies with the ANSI standard.
  10. Source:
  11. __cplusplus: This macro is defined when the compiler is in C++ mode.
  12. Source: These predefined macros are useful for conditional compilation and for obtaining information about the compilation process and environment.