|
|||
Specification of search rules for C/C++ include directiveIntroductionMost C and C++ compilers interpret the #include "..." preprocessor directive to mean ``look for the specified include file first in the directory of the including file, then search using #include <...> search rules.'' This behavior is incompatible with ``viewpathing'', which requires the ability to override the included file with a file in a another directory (typically a file in a closer viewpath node.) This document specifies modified include directive search rules that provide the needed functionality. Enabling the modified search rulesThe -I- compiler option-I- search rules are enabled when the -I- argument appears on the compilation command line. Search directories are specified to a compiler through a sequence of command line arguments of the form:
-Ilcl1 -Ilcl2 ... -Ilcln -I- -Istd1 -Istd2 ... -Istdn
This is similar to the -I option currently used by many C/C++ compilers, except that a -I- option appears within the -I list, beginning of the list, or at the end of the list. The prefixinclude compiler optionFor all known compilers, prefixinclude processing is required when -I- search rules are in effect. Consequently, prefixinclude processing should be automatically enabled when -I- processing is turned on. Conversely, there is no known requirement for prefixinclude processing without -I-. Therefore, currently we see no need for a separate compiler option to turn on prefixinclude. TerminologyThe following terms are used in the search rules specification:
Search rules when -I- is specifiedNote: currently there are no known compilers which require -I- search rule processing without also requiring prefixinclude processing. This section is included only to clarify the meaning of -I- without the extra complications of prefixinclude. Files included using #include "..." are searched using the following directory search paths in the following order:
Do not look in the directory of the including file. Files included using #include <...> are searched using the following directory search paths in the following order:
For both "..." and <...> style includes, if the include file path is an absolute path (path begins with a '/'), do not follow the usual search rules. Just use the named file without any search. Search rules when -I- is specified and prefixinclude option is in effectThis rule reduces to the non-prefixinclude case stated previously when all include path prefixes in a compilation are ".". The only differences are: 1) we maintain a prefix path for each input file and 2) we perform an additional search step when a file is included using "..." and the prefix path of the including file is not ".". Initialize the prefix path of the primary source file to ".".
if (file included using #include "...") {
if (prefix path of the including file is not ".") {
} /* end ``file included using #include "..."'' */
Form a localized include file path by concatenating the prefix path of the including file and the include file path, in that order. This will form a new relative path containing the prefix path of the including file, a "/", and the include file path. Search for the localized include file path using the following directory search paths in the following order:
If found, set the prefix path of the newly found included file to the concatenation of the prefix path of the including file and the include path prefix. (This allows the included file to ``inherit'' the prefix path of its including file.) Search for the original include file path using the following directory search paths in the following order:
As before, do not look in the directory of the including file. If found, set the prefix path of the newly found included file to the include path prefix.
if (file included using #include <...>) {
As in the nonprefixinclude case, search using the following directory search paths in the following order:
If found, set the prefix path of the newly found included file to the include path prefix. During path concatenation operations, the usual path optimizations such as "./x" => "x" and "x/../y" => "y" may be performed. For both "..." and <...> style includes, if the include file path is an absolute path (path begins with a '/'), do not follow the usual search rules. Just use the named file without any search. Set the prefix path of newly found included file to ".". Last Update: Wednesday,20-Dec-06 13:22:03 CST
|
|||