{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

‘#line ’(see chapter 6[line control page 44 does

Info iconThis preview shows pages 13–15. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ‘ #line ’ (see Chapter 6 [Line Control], page 44 ) does not change GCC’s idea of the directory containing the current file. You may put ‘-I- ’ at any point in your list of ‘-I ’ options. This has two effects. First, directories appearing before the ‘-I- ’ in the list are searched only for headers requested Chapter 2: Header Files 10 with quote marks. Directories after ‘-I- ’ are searched for all headers. Second, the directory containing the current file is not searched for anything, unless it happens to be one of the directories named by an ‘-I ’ switch. ‘-I- ’ is deprecated, ‘-iquote ’ should be used instead. ‘-I. -I- ’ is not the same as no ‘-I ’ options at all, and does not cause the same behavior for ‘ <> ’ includes that ‘ "" ’ includes get with no special options. ‘-I. ’ searches the compiler’s current working directory for header files. That may or may not be the same as the directory containing the current file. If you need to look for headers in a directory named ‘- ’, write ‘-I./- ’. There are several more ways to adjust the header search path. They are generally less useful. See Chapter 12 [Invocation], page 56 . 2.4 Once-Only Headers If a header file happens to be included twice, the compiler will process its contents twice. This is very likely to cause an error, e.g. when the compiler sees the same structure definition twice. Even if it does not, it will certainly waste time. The standard way to prevent this is to enclose the entire real contents of the file in a conditional, like this: /* File foo. */ #ifndef FILE_FOO_SEEN #define FILE_FOO_SEEN the entire file #endif /* !FILE_FOO_SEEN */ This construct is commonly known as a wrapper #ifndef . When the header is included again, the conditional will be false, because FILE_FOO_SEEN is defined. The preprocessor will skip over the entire contents of the file, and the compiler will not see it twice. CPP optimizes even further. It remembers when a header file has a wrapper ‘ #ifndef ’. If a subsequent ‘ #include ’ specifies that header, and the macro in the ‘ #ifndef ’ is still defined, it does not bother to rescan the file at all. You can put comments outside the wrapper. They will not interfere with this optimiza- tion. The macro FILE_FOO_SEEN is called the controlling macro or guard macro . In a user header file, the macro name should not begin with ‘ _ ’. In a system header file, it should begin with ‘ __ ’ to avoid conflicts with user programs. In any kind of header file, the macro name should contain the name of the file and some additional text, to avoid conflicts with other header files. 2.5 Alternatives to Wrapper #ifndef CPP supports two more ways of indicating that a header file should be read only once....
View Full Document

{[ snackBarMessage ]}

Page13 / 83

‘#line ’(see Chapter 6[Line Control page 44 does not...

This preview shows document pages 13 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online