{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

28 system headers the header files declaring

Info icon This preview shows pages 17–19. Sign up to view the full content.

View Full Document Right Arrow Icon
2.8 System Headers The header files declaring interfaces to the operating system and runtime libraries often can- not be written in strictly conforming C. Therefore, GCC gives code found in system headers special treatment. All warnings, other than those generated by ‘ #warning ’ (see Chapter 5 [Diagnostics], page 43 ), are suppressed while GCC is processing a system header. Macros defined in a system header are immune to a few warnings wherever they are expanded. This immunity is granted on an ad-hoc basis, when we find that a warning generates lots of false positives because of code in macros defined in system headers. Normally, only the headers found in specific directories are considered system headers. These directories are determined when GCC is compiled. There are, however, two ways to make normal headers into system headers. The ‘ -isystem ’ command line option adds its argument to the list of directories to search for headers, just like ‘ -I ’. Any headers found in that directory will be considered system headers. All directories named by ‘ -isystem ’ are searched after all directories named by ‘ -I ’, no matter what their order was on the command line. If the same directory is named by both -I ’ and ‘ -isystem ’, the ‘ -I ’ option is ignored. GCC provides an informative message when this occurs if ‘ -v ’ is used. There is also a directive, #pragma GCC system_header , which tells GCC to consider the rest of the current include file a system header, no matter where it was found. Code that comes before the ‘ #pragma ’ in the file will not be affected. #pragma GCC system_header has no effect in the primary source file. On very old systems, some of the pre-defined system header directories get even more special treatment. GNU C ++ considers code in headers found in those directories to be surrounded by an extern "C" block. There is no way to request this behavior with a #pragma ’, or from the command line. 3 Macros A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look like when they are used. Object-like macros resemble data objects when used, function-like macros resemble function calls. You may define any valid identifier as a macro, even if it is a C keyword. The preprocessor does not know anything about keywords. This can be useful if you wish to hide a keyword such as const from an older compiler that does not understand it. However, the preprocessor operator defined (see Section 4.2.3 [Defined], page 42 ) can never be defined as a macro, and C ++ ’s named operators (see Section 3.7.4 [C ++ Named Operators], page 32 ) cannot be macros when you are compiling C ++ .
Image of page 17

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

View Full Document Right Arrow Icon
Chapter 3: Macros 14 3.1 Object-like Macros An object-like macro is a simple identifier which will be replaced by a code fragment. It is called object-like because it looks like a data object in code that uses it. They are most commonly used to give symbolic names to numeric constants.
Image of page 18
Image of page 19
This is the end of the preview. Sign up to access the rest of the document.

{[ 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