more compiler switches

F

frank

I've been looking through gcc.pdf for a head-splitting half hour and
cannot find the command-line switch that tells you what all is defined
as preprocessing turns into compilation. In my own defense, the
switches are divided up into preprocessing, compiling, and
environmental, and this sits on the bubble with all 3.

I certainly noticed the -I switch, which would have saved me a lot of
grief this week, to say nothing of looking like a buffoon.

TIA
--
 
K

Keith Thompson

frank said:
I've been looking through gcc.pdf for a head-splitting half hour and
cannot find the command-line switch that tells you what all is defined
as preprocessing turns into compilation. In my own defense, the
switches are divided up into preprocessing, compiling, and
environmental, and this sits on the bubble with all 3.

I certainly noticed the -I switch, which would have saved me a lot of
grief this week, to say nothing of looking like a buffoon.

See my followup in gnu.gcc.help.
 
K

Kenny McCormack

I've been looking through gcc.pdf for a head-splitting half hour and
cannot find the command-line switch that tells you what all is defined
as preprocessing turns into compilation. In my own defense, the
switches are divided up into preprocessing, compiling, and
environmental, and this sits on the bubble with all 3.

I certainly noticed the -I switch, which would have saved me a lot of
grief this week, to say nothing of looking like a buffoon.

TIA
--

Are you looking for -E?
 
F

frank

Kenny said:
Are you looking for -E?
dan@dan-desktop:~/source/unleashed/ch11$ gcc -E kenny1.c -o k
dan@dan-desktop:~/source/unleashed/ch11$ cat kenny1.c
#include <stdio.h>

int main(void)

{

printf("necessary execution\n");
return 0;

}

/* -E -Xpreprocessor -dM
gcc -E kenny1.c -o k */
dan@dan-desktop:~/source/unleashed/ch11$

If -E worked, I would expect to see something after the compilation
command is given.

??
 
S

Seebs

dan@dan-desktop:~/source/unleashed/ch11$ gcc -E kenny1.c -o k

This should dump output in a file called "k". ("-o X" is gcc's way
of spelling "dump output in X".)
If -E worked, I would expect to see something after the compilation
command is given.

No. You're on a Unix-like system. Most commands, if they work, indicate
this by being silent. Look at the output file you specified. And possibly
take this to gnu.gcc.help, since this is nothing to do with the language
per se.

-s
 
J

jaysome

I've been looking through gcc.pdf for a head-splitting half hour and
cannot find the command-line switch that tells you what all is defined
as preprocessing turns into compilation. In my own defense, the
switches are divided up into preprocessing, compiling, and
environmental, and this sits on the bubble with all 3.

I certainly noticed the -I switch, which would have saved me a lot of
grief this week, to say nothing of looking like a buffoon.

TIA

The following works for me.

For gcc on UNIX, Linux, Mac OS X and so on:

gcc -dM -E - < /dev/null

For gcc on Windows:

gcc -dM -E - < /nul
 
A

Antoninus Twink

See my followup in gnu.gcc.help.

You're so funny, Keith.

I've copied your response to both groups for the benefit of readers
(like me) who don't subscribe to ggh but are interested in the C
discussion.
gcc.pdf? The documentation for gcc is generally in "info" format;
perhaps you have a pdf that was generated from that?

The proprocessor, "cpp" is documented seperately from gcc.

In the gcc documentation, look for "Options Controlling the
Preprocessor" to see how to pass options to cpp. You can use either
"-Wp,OPTION" or "-Xpreprocessor OPTION"; I haven't figured out what
the difference is.

Did you try reading that documentation yourself?

-Wp,option lets you pass a fixed set of options to the preprocessor -
those known by the gcc compiler driver.

-Xpreprocessor option will pass options verbatim, whether or not they
are available by a gcc driver flag.
 
F

frank

Seebs said:
This should dump output in a file called "k". ("-o X" is gcc's way
of spelling "dump output in X".)


No. You're on a Unix-like system. Most commands, if they work, indicate
this by being silent. Look at the output file you specified. And possibly
take this to gnu.gcc.help, since this is nothing to do with the language
per se.

-s

You don't think there exists a state between preprocessing and
compilation as indicated by the machine model?

I find your replies usually errant.
 
N

Nick

frank said:
You don't think there exists a state between preprocessing and
compilation as indicated by the machine model?

I find your replies usually errant.

There may be no requirement for such a state, although it clearly exists
conceptually, but gcc is certainly can be made to output such code.

It's worth pointing out that this -E option does not give you the pure
pre-processor output such that you could put it into any old compiler.
It contains a lot of # prefixed lines used for gcc's internal purposes
(showing where things have come from I think).
 
K

Keith Thompson

frank said:
You don't think there exists a state between preprocessing and
compilation as indicated by the machine model?

I'm not even sure what that means.
I find your replies usually errant.

I don't. In fact, everything he says above is correct.

In any case, I answered your question (or tried to) in gnu.gcc.help.
If you have any more questions, I can probably answer them there.
 
S

Seebs

You don't think there exists a state between preprocessing and
compilation as indicated by the machine model?

Well, actually, not really, no. If you look at the standard, you'll notice
a number of "phases of translation". You have picked an arbitrary phase,
and asserted that you want to look at the output of that phase -- but you'll
note that there's nothing special about that phase intrinsically. Many
compilers are indeed structured so that the "preprocessing phase" produces
output, which is then fed to another program, but this implementation is
not required. I've used implementations where it wasn't really so.

However, even if it were true that every single compiler provided some way
to obtain "preprocessed output"... Your question is fundamentally not about
the language, but about a specific compiler and/or a specific shell. The
distinction between "gcc -E foo.c -o foo.i" and "gcc -E < foo.c > foo.i"
is purely a question of UNIX and gcc semantics, and has nothing to do with
C; you might as well be asking about "dd if=foo.c of=foo.i" vs. "dd < foo.c >
foo.i".

So really, your question here is more about gcc (or the shell) than about
C. Advice useful to you would be useless to someone using lcc-win or Visual
C++. Advice from users of those would be useless to you. That's usually a
sign that your question is about a particular program, rather than about
the language.
I find your replies usually errant.

Odd.

-s
 
F

frank

Seebs said:
snip


Odd.

-s

I wanted to apologize for the tone of this comment. Number one, you're
a nice guy and two, you're knowledgeable about C. (I suspect that you
could be a dynamite sounding board for me as I go about trying to work
up a bag of tricks with unix, and I don't want to burn a bridge.)

I go through periods where I just don't see eye to eye with others here
on certain issues, while we otherwise agree on so much else, for
example, the value of using and talking standard C.
 
F

frank

Now I'm re-reading what you wrote. My misunderstanding was that I
thought the switch was like -v, where you have the same command as when
you create an executable whose name is specified by -o:

gcc -v kenny1.c -o k

This creates an executable named k and sends all the commments to stdout.

I haven't tried it yet, but now I think the solution is

gcc -E kenny1.c
I'm not even sure what that means.

A state is the sum total of the values in it.
I don't. In fact, everything he says above is correct.

This was intemperate of me.
 
F

frank

Kenny said:
Are you looking for -E?
# 882 "/usr/include/stdio.h" 3 4
extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__));



extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__)) ;


extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__));
# 912 "/usr/include/stdio.h" 3 4

# 2 "kenny1.c" 2



int main(void)

{

printf("necessary execution\n");
return 0;

}
dan@dan-desktop:~/source/unleashed/ch11$

Yes I was. You're -o k, kenny.
 
S

Seebs

I wanted to apologize for the tone of this comment.

No worries, it's very hard to offend me.

Anyway, in this case, I was making a specific point about the nature of
your question. In practice, 99% of the C work I do is in an environment
where not only is preprocessing a discrete phase, but it's easy to get
at the preprocessed output. (Using, in fact, gcc -E.) But I think it's
also useful to be aware that such a thing is related to a specific
compiler, because that can sometimes lead you to a useful piece of
information. You might, for instance, benefit a lot from reading
gnu.gcc.help (for gcc information), and possibly something like
comp.unix.shell (for more information about command lines, such as
what the difference between "-o foo" and "> foo" is).

-s
 
S

Seebs

Now I'm re-reading what you wrote. My misunderstanding was that I
thought the switch was like -v, where you have the same command as when
you create an executable whose name is specified by -o:

gcc -v kenny1.c -o k

This creates an executable named k and sends all the commments to stdout.

Seems likely.
I haven't tried it yet, but now I think the solution is

gcc -E kenny1.c

That would show output on stdout. If you do "-o k", it'll go into a
file. I usually use -o.

By convention:
gcc -E foo.c -o foo.i # preprocessed source
gcc -s foo.c -o foo.s # assembly
gcc -c foo.c -o foo.o # object code
gcc foo.c -o foo # executable

Note that in general, gcc will take any of these as inputs and probably do
the right thing. Note also that none of this is particularly topical here,
so followups to gnu.gcc.help.

-s
 
F

frank

jaysome said:
The following works for me.

For gcc on UNIX, Linux, Mac OS X and so on:

gcc -dM -E - < /dev/null

For gcc on Windows:

gcc -dM -E - < /nul

An interesting post, jaysome, I had to go elsegroup to figure out what
you were doing here. In my linuxlog I have it so:

gcc -dM -E - < /dev/null

shows predefined macros

for windows

gcc -dM -E - < /nul

Thx,
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top