How to use the cpponly compiler pragma

K

kris

Hi,

I just want to know how to use the the CPPONLY pragma which causes only
the C macro preprocessor to be run. Can you specify an example.


Thanks in advance
 
K

Keith Thompson

kris said:
I just want to know how to use the the CPPONLY pragma which causes only
the C macro preprocessor to be run. Can you specify an example.

There is no CPPONLY pragma in standard C. It may be some
compiler-specific extension.

Followups redirected.
 
K

kris

Then how can we obtain a preprocessed output of a programm using a
standard c-compiler.
 
G

Glenn Hutchings

kris said:
Then how can we obtain a preprocessed output of a programm using a
standard c-compiler.

It depends on the C compiler. For example, gcc has a -E option which
says "just preprocess things".

Glenn
 
J

Jordan Abel

2006-11-03 said:
It depends on the C compiler. For example, gcc has a -E option which
says "just preprocess things".

Rarely, using the preprocessor output will yield different results. For
example,

#define N 0xE

main() {
printf("%d\n",N+1);
return 0;
}

The output will be 15, but if the preprocessor intermediate output is
taken, we have the token 0xE+1 in source, which is an invalid number.
gcc -E seems to get around this by adding a space, but is this legal?
 
J

Jean-Marc Bourguet

Jordan Abel said:
Rarely, using the preprocessor output will yield different results. For
example,

#define N 0xE

main() {
printf("%d\n",N+1);
return 0;
}

The output will be 15, but if the preprocessor intermediate output is
taken, we have the token 0xE+1 in source, which is an invalid number.
gcc -E seems to get around this by adding a space, but is this legal?

The standard does not describe the preprocessor as processing text but
as processing tokens. gcc -E gives a textual output which when
tokenized provide the same streams of tokens as preprocessing the
original file.

Yours,
 
J

Jordan Abel

2006-11-03 said:
The standard does not describe the preprocessor as processing text but
as processing tokens.

I think it does describe how whitespace is treated. Comments, for
example, are defined as expanding to a space, _not_ as being an
invisible token splitter. I don't think macro expansions are defined as
being expanded surrounded by whitespace, "if necessary" or otherwise.
Now, the only way to tell is to use the stringize operator, so let's
come up with an example

#define N 0xE
#define s(x) #x
#define S(x) s(x)
S(a/**/b)
S(N+1)

is the case I was thinking of, but GCC seems to handle this properly. We
have "a b" and "0xE+1".
gcc -E gives a textual output which when tokenized provide the same
streams of tokens as preprocessing the original file.

And it seems smart enough to only do it when there can be no visible
difference (i.e. not under stringize). That was what I was worried
about. Anyway, other compilers might not be as smart, and using the
"preprocessor only" output may result in text output that cannot be
retokenized properly.
 
A

Al Balmer

Then how can we obtain a preprocessed output of a programm using a
standard c-compiler.
You start by reading the documentation for whatever compiler you're
using.
 
J

Jean-Marc Bourguet

Jordan Abel said:
I think it does describe how whitespace is treated. Comments, for
example, are defined as expanding to a space, _not_ as being an
invisible token splitter.

There are some place where the presence of whitespace (if my memory is
good, comments are white space for that purpose) is significant but it
doesn't go further than that. One hint is the presence of the ##
operator.
I don't think macro expansions are defined as being expanded
surrounded by whitespace, "if necessary" or otherwise.

They are defined as producing a sequence of (preprocessing) tokens.
And it seems smart enough to only do it when there can be no visible
difference (i.e. not under stringize). That was what I was worried
about. Anyway, other compilers might not be as smart, and using the
"preprocessor only" output may result in text output that cannot be
retokenized properly.

Some compilers have the preprocessor as a separate programs which feed
the compiler, these must have a correct preprocessor.

Yours,
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top