{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Comments and string literals which have not been

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

View Full Document Right Arrow Icon
must consist of complete tokens. Comments and string literals which have not been closed by the end of an included file are invalid. For error recovery, they are considered to end at the end of the file. To avoid confusion, it is best if header files contain only complete syntactic units— function declarations or definitions, type declarations, etc. The line following the ‘ #include ’ directive is always treated as a separate line by the C preprocessor, even if the included file lacks a final newline. 2.3 Search Path GCC looks in several different places for headers. On a normal Unix system, if you do not instruct it otherwise, it will look for headers requested with #include < file > in: /usr/local/include libdir /gcc/ target / version /include /usr/ target /include /usr/include For C ++ programs, it will also look in ‘ libdir /../include/c++/ version ’, first. In the above, target is the canonical name of the system GCC was configured to compile code for; often but not always the same as the canonical name of the system it runs on. version is the version of GCC in use. You can add to this list with the ‘ -I dir ’ command line option. All the directories named by ‘ -I ’ are searched, in left-to-right order, before the default directories. The only exception is when ‘ dir ’ is already searched by default. In this case, the option is ignored and the search order for system directories remains unchanged. Duplicate directories are removed from the quote and bracket search chains before the two chains are merged to make the final search chain. Thus, it is possible for a directory to occur twice in the final search chain if it was specified in both the quote and bracket chains. You can prevent GCC from searching any of the default directories with the ‘ -nostdinc option. This is useful when you are compiling an operating system kernel or some other program that does not use the standard C library facilities, or the standard C library itself. -I ’ options are not ignored as described above when ‘ -nostdinc ’ is in effect. GCC looks for headers requested with #include " file " first in the directory containing the current file, then in the directories as specified by ‘ -iquote ’ options, then in the same places it would have looked for a header requested with angle brackets. For example, if /usr/include/sys/stat.h ’ contains #include "types.h" , GCC looks for ‘ types.h ’ first in ‘ /usr/include/sys ’, then in its usual search path. #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
Background image of page 13

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

View Full Document Right Arrow Icon
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, ‘
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}