Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

more compiler switches

0 views
Skip to first unread message

frank

unread,
Jan 22, 2010, 8:44:35 PM1/22/10
to
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
--

Kenny McCormack

unread,
Jan 22, 2010, 9:38:02 PM1/22/10
to
In article <7rv2k4...@mid.individual.net>,

Are you looking for -E?

Keith Thompson

unread,
Jan 22, 2010, 9:37:14 PM1/22/10
to

See my followup in gnu.gcc.help.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

frank

unread,
Jan 22, 2010, 11:08:06 PM1/22/10
to
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.

??
--
frank

Seebs

unread,
Jan 23, 2010, 12:24:38 AM1/23/10
to
On 2010-01-23, frank <fr...@example.invalid> wrote:
> 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
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

jaysome

unread,
Jan 23, 2010, 12:55:47 AM1/23/10
to
On Fri, 22 Jan 2010 18:44:35 -0700, frank <fr...@example.invalid>
wrote:

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

--
jay

Antoninus Twink

unread,
Jan 23, 2010, 4:30:12 AM1/23/10
to
On 23 Jan 2010 at 2:36, Keith Thompson wrote:

> frank <fr...@example.invalid> writes:
>> 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.
>
> 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.

> You'll also want to use "-E" so the output of the preprocessor goes to
> stdout rather than being processed by the rest of the compiler.
>
> The preprocessor option you're looking for can be found in the
> "Invocation" section of the cpp document; it's "-dM".
>
> So you can use any of:
>
> gcc -E -Xpreprocessor -dM <filename>
> gcc -E -Wp,-dM <filename>
> cpp -dM <filename>

frank

unread,
Jan 23, 2010, 5:17:43 AM1/23/10
to
Seebs wrote:
> On 2010-01-23, frank <fr...@example.invalid> wrote:
>> 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

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

I find your replies usually errant.
--
frank

Nick

unread,
Jan 23, 2010, 5:24:44 AM1/23/10
to
frank <fr...@example.invalid> writes:

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).
--
Online waterways route planner | http://canalplan.eu
Plan trips, see photos, check facilities | http://canalplan.org.uk

Keith Thompson

unread,
Jan 23, 2010, 5:26:20 AM1/23/10
to
frank <fr...@example.invalid> writes:
> Seebs wrote:
>> On 2010-01-23, frank <fr...@example.invalid> wrote:
>>> 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.
>
> 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.

Seebs

unread,
Jan 23, 2010, 2:26:40 PM1/23/10
to
On 2010-01-23, frank <fr...@example.invalid> wrote:
> 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.

frank

unread,
Jan 23, 2010, 9:38:52 PM1/23/10
to
Seebs wrote:
> On 2010-01-23, frank <fr...@example.invalid> wrote:

snip

>> I find your replies usually errant.
>
> 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.
--
frank

frank

unread,
Jan 23, 2010, 10:11:18 PM1/23/10
to
Keith Thompson wrote:
> frank <fr...@example.invalid> writes:
>> Seebs wrote:
>>> On 2010-01-23, frank <fr...@example.invalid> wrote:
>>>> 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.

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

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

A state is the sum total of the values in it.


>
>> I find your replies usually errant.
>
> I don't. In fact, everything he says above is correct.

This was intemperate of me.
--
frank

frank

unread,
Jan 23, 2010, 10:13:46 PM1/23/10
to
# 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.
--
frank

Seebs

unread,
Jan 23, 2010, 10:37:17 PM1/23/10
to
On 2010-01-24, frank <fr...@example.invalid> wrote:
> 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).

Seebs

unread,
Jan 23, 2010, 11:45:20 PM1/23/10
to
On 2010-01-24, frank <fr...@example.invalid> wrote:
> 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.

lawrenc...@siemens.com

unread,
Jan 24, 2010, 3:33:06 PM1/24/10
to
Seebs <usenet...@seebs.net> wrote:
>
> No worries, it's very hard to offend me.

Oh boy, a challenge! :-)
--
Larry Jones

I've got to start listening to those quiet, nagging doubts. -- Calvin

frank

unread,
Jan 26, 2010, 11:25:34 PM1/26/10
to

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,
--
frank

0 new messages