On Wed, 09 Jun 2004 14:06:37 GMT,
rl*@hoekstra-uitgeverij.nl (Richard
Bos) wrote in comp.lang.c:
"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote:
In fact, AFAICT the OP's code is *not* correct. Since when is
#include "stdio.h"
the appropriate way to get a prototype in scope for 'printf', a function
defined in the header <stdio.h>? The OP's code would be perfectly
correct were he to have written
#define HEADERFILE <stdio.h>
#include HEADERFILE
From (a draft of) C89:
# A preprocessing directive of the form
#
# # include "q-char-sequence" new-line
#
#causes the replacement of that directive by the entire contents of the
#source file identified by the specified sequence between the
#delimiters. The named source file is searched for in an
#implementation-defined manner. If this search is not supported, or if
#the search fails, the directive is reprocessed as if it read
#
# # include <h-char-sequence> new-line
#
#with the identical contained sequence (including > characters, if any)
#from the original directive.
Richard
Your quotation is basically correct, but your conclusion is not,
according to the standard. It happens to work on most
implementations, because the C standard headers are supplied as text
files for the majority of them.
Here is the relevant text from the C99 standard, including material
above what you quoted:
<begin quote>
6.10.2 Source file inclusion
Constraints
1 A #include directive shall identify a header or source file that can
be processed by the implementation.
Semantics
2 A preprocessing directive of the form
# include <h-char-sequence> new-line
searches a sequence of implementation-defined places for a header
identified uniquely by the specified sequence between the < and >
delimiters, and causes the replacement of that directive by the entire
contents of the header. How the places are specified or the header
identified is implementation-defined.
3 A preprocessing directive of the form
# include "q-char-sequence" new-line
causes the replacement of that directive by the entire contents of the
source file identified by the specified sequence between the "
delimiters. The named source file is searched for in an
implementation-defined manner. If this search is not supported, or if
the search fails, the directive is reprocessed as if it read
# include <h-char-sequence> new-line
with the identical contained sequence (including > characters, if any)
from the original directive.
<end quote>
Note the distinction between "headers" (which need not be files) which
are included with the #include <> directive, and source files which
may be included with the #include "" directive.
There is no guarantee that:
#include "stdio.h"
....will include the standard C header <stdio.h> into the source and
make the corresponding library functions available with proper
prototypes.
Specifically, if the implementation-defined methods of search and file
or file identification happen to come across some random file _not_
provided by the implementation as a standard header, and includes it
as a source file, the behavior is completely undefined.
#include <stdio.h>
....is conforming and guaranteed to properly include the standard
header.
#include "stdio.h"
....is not, and is not required to be accepted by a conforming
implementation.
This is true of all 15, 18, or 24 standard headers for C89/90, 95, and
99 respectively.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html