K
Keith Thompson
frank said:4 A preprocessing directive of the form
# include pp-tokens new-line
(that does not match one of the two previous forms) is
permitted. The preprocessing tokens after include in the directive
are processed just as in normal text. (Each identifier currently
defined as a macro name is replaced by its replacement list of
preprocessing tokens.) The directive resulting after all
replacements shall match one of the two previous forms.148) The
method by which a sequence of preprocessing tokens between a < and a
into a single header name preprocessing token is
implementation-defined.
Apparently pp-tokens is the output from a preprocessor.
Yes. The syntax rule
# include pp-tokens new-line
refers to them because #include directives are handled by the
proprocessor; the pp-tokens haven't been converted to tokens.
I think I've
figured out why #includes don't just include files.
I don't think you have. The pp-tokens in question are just the ones
that appear in the #include directive itself; they have nothing to do
with the contents or origin of the header. It's really just saying
that in either
#include "header"
or
include <header>
the "header" or <header> can be the result of macro expansion. For
example, this is valid:
#define STDIO <stdio.h>
#include STDIO
This had to be described as a special rule because both macro
expansion and #include expansion happen during the same translation
phase. If #include expansion happened in a later phase than
macro expansion, the third form would follow naturally from the
existing rules.
A header can be anything the compiler permits it to be. It's
typically a C source file, but it can be a binary file that the
compiler is able to interpret, or it can be purely internal to the
compiler. For example, the compiler, on seeing
#include <stdbool.h>
might just internally generate the appropriate macro definitions
without reading any external file. Or the compiler might use actual
files for all headers; other methods are permitted but not required.
Doesn't cpp hand
gcc a bunck of tokens that aren't in any file?
I'm not sure, but I don't think so. As you've seen, it does predefine
certain macros, but that's not the same thing.