The #include directive

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.
 
F

Flash Gordon

Keith said:
Anything.

One common option is a pre-compiled header, which might be in some form
of simple database. For some options without pre-compiled headers see
the discussions about things done under VMS in this very thread!
 
R

Richard Tobin

Footnote 1: System includes need not actually be files, but the effect
is always the same.
[/QUOTE]
If they're not necessarliy files, what can they be?

For example, they might be built in to the compiler: when it sees
#include <stdio.h> it might just make the relevant declarations
visible.

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top