C has 17 standard headers (<stdio.h>, <string.h>, <stdlib.h>, and others). These headers are delivered as part of Solaris, in the directory /usr/include. C++ has those same headers, with the added requirement that the various declared names appear in both the global namespace and in namespace std. For logistical reasons, the C++ compiler supplies its own versions of these headers instead of replacing those in the /usr/include directory.
C++ also has a second version of each of the C standard headers (<cstdio>, <cstring>, and <cstdlib>) with the various declared names appearing only in namespace std. Finally, C++ adds 32 of its own standard headers (<string>, <utility>, <iostream>).
The obvious implementation of the standard headers would use the name found in C++ source code as the name of a text file to be included. For example, the standard header <string> would refer to a file named string in some directory. That obvious implementation has the following drawbacks:
You cannot search for just header files or create a makefile rule for them if they do not have file name suffixes.
If you put -I/usr/include on the compiler command line, you don't get the correct version of the standard C headers because /usr/include is searched before the compiler's own include directory.
If you have a directory or executable program named string, it might erroneously be found instead of the standard header file.
The default dependencies for makefiles when .KEEP_STATE is enabled can result in attempts to replace standard headers with an executable program. (A file without a suffix is assumed by default to be a program to be built.)
To solve these problems, the compiler include directory contains a file with the same name as the header, along with a symbolic link to it that has the unique suffix ".SUNWCCh." (SUNW is the prefix for all compiler-related packages, CC is the C++ compiler, and .h is the usual suffix for header files). When you specify <string>, the compiler rewrites it to <string.SUNWCCh> and searches for that name. The suffixed name will be found only in the compiler's own include directory. If the file so found is a symbolic link (which it normally is), the compiler dereferences the link exactly once and uses the result (string in this case) as the file name for error messages and debugger references. The compiler uses the suffixed name when emitting file dependency information.
The name rewriting occurs only for the two forms of the 17 standard C headers and the 32 standard C++ headers, only when they appear in angle brackets and without any path specified. If you use quotes instead of angle brackets, specify any path components, or specify some other header, no rewriting occurs. The following table illustrates common situations.
Source code |
Compiler searches for |
Comments |
---|---|---|
<string> |
string.SUNWCCh |
C++ string templates |
<cstring> |
cstring.SUNWCCh |
A version of C string.h |
<string.h> |
string.h.SUNWCCh |
C string.h |
<fcntl.h> |
fcntl.h |
Not a standard C or C++ header |
"string" |
string |
Quotes, not angle bracket |
<../string> |
../string |
Path specified |