Gfortran the gnu fortran compiler defines this gnuc

Info icon This preview shows pages 27–29. Sign up to view the full content.

headers will not be used. __GFORTRAN__ The GNU Fortran compiler defines this. __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ These macros are defined by all GNU compilers that use the C preproces- sor: C, C ++ , Objective-C and Fortran. Their values are the major version, minor version, and patch level of the compiler, as integer constants. For ex- ample, GCC 3.2.1 will define __GNUC__ to 3, __GNUC_MINOR__ to 2, and __ GNUC_PATCHLEVEL__ to 1. These macros are also defined if you invoke the preprocessor directly. __GNUC_PATCHLEVEL__ is new to GCC 3.0; it is also present in the widely-used development snapshots leading up to 3.0 (which identify themselves as GCC 2.96 or 2.97, depending on which snapshot you have). If all you need to know is whether or not your program is being compiled by GCC, or a non-GCC compiler that claims to accept the GNU C dialects, you can simply test __GNUC__ . If you need to write code which depends on a specific version, you must be more careful. Each time the minor version is increased, the patch level is reset to zero; each time the major version is increased (which happens rarely), the minor version and patch level are reset. If you wish to use the predefined macros directly in the conditional, you will need to write it like this: /* Test for GCC > 3.2.0 */ #if __GNUC__ > 3 || \ (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \ (__GNUC_MINOR__ == 2 && \ __GNUC_PATCHLEVEL__ > 0)) Another approach is to use the predefined macros to calculate a single number, then compare that against a threshold: #define GCC_VERSION (__GNUC__ * 10000 \ + __GNUC_MINOR__ * 100 \ + __GNUC_PATCHLEVEL__) ...
Image of page 27

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Chapter 3: Macros 24 /* Test for GCC > 3.2.0 */ #if GCC_VERSION > 30200 Many people find this form easier to understand. __GNUG__ The GNU C ++ compiler defines this. Testing it is equivalent to testing (__GNUC__ && __cplusplus) . __STRICT_ANSI__ GCC defines this macro if and only if the ‘ -ansi ’ switch, or a ‘ -std ’ switch specifying strict conformance to some version of ISO C or ISO C ++ , was specified when GCC was invoked. It is defined to ‘ 1 ’. This macro exists primarily to direct GNU libc’s header files to restrict their definitions to the minimal set found in the 1989 C standard. __BASE_FILE__ This macro expands to the name of the main input file, in the form of a C string constant. This is the source file that was specified on the command line of the preprocessor or C compiler. __INCLUDE_LEVEL__ This macro expands to a decimal integer constant that represents the depth of nesting in include files. The value of this macro is incremented on every #include ’ directive and decremented at the end of every included file. It starts out at 0, its value within the base file specified on the command line. __ELF__ This macro is defined if the target uses the ELF object format. __VERSION__ This macro expands to a string constant which describes the version of the compiler in use. You should not rely on its contents having any particular form, but it can be counted on to contain at least the release number.
Image of page 28
Image of page 29
This is the end of the preview. Sign up to access the rest of the document.
  • Summer '13
  • Noone
  • GCC, C preprocessor

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern