public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Making gcc read from the standard input
@ 2007-01-11  6:31 Tathagato Rai Dastidar
  2007-01-11  9:12 ` Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tathagato Rai Dastidar @ 2007-01-11  6:31 UTC (permalink / raw)
  To: gcc-help, gcc

Hello,

Is there a way I can make GCC read a C or C++ code from the standard input 
instead of from a file?

In my application software, I am generating some C code on the fly, writing it 
to a file, then using GCC to compile it. Instead of that, I want to invoke GCC 
through a pipe, and write the C code directly into GCC, instead of writing it 
into a file and then calling GCC.

Is this possible?

Regards,
Tathagato Rai Dastidar
Prinicipal Software Engineer,
National Semiconductor Corp.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Making gcc read from the standard input
  2007-01-11  6:31 Making gcc read from the standard input Tathagato Rai Dastidar
@ 2007-01-11  9:12 ` Paolo Bonzini
  2007-01-11 13:56 ` John Love-Jensen
  2007-01-11 17:06 ` Mike Stump
  2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2007-01-11  9:12 UTC (permalink / raw)
  To: Tathagato Rai Dastidar, gcc-help, GCC Development

Tathagato Rai Dastidar wrote:
> Hello,
> 
> Is there a way I can make GCC read a C or C++ code from the standard 
> input instead of from a file?
> 
> In my application software, I am generating some C code on the fly, 
> writing it to a file, then using GCC to compile it. Instead of that, I 
> want to invoke GCC through a pipe, and write the C code directly into 
> GCC, instead of writing it into a file and then calling GCC.
> 
> Is this possible?

This is a question only for gcc-help.  Cross-posting gcc and gcc-help is 
almost always wrong.  :-) But yes, it is possible by adding "-x c" to 
the command line, so that the gcc driver knows which front-end to 
invoke.  In the case of "-E", in fact, GCC implicitly considers the 
language to be C (and invokes the C front-end) because the preprocessor 
is the same for all input languages; but for real compilation, you need 
to specify the language manually.

HTH,

Paolo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Making gcc read from the standard input
  2007-01-11  6:31 Making gcc read from the standard input Tathagato Rai Dastidar
  2007-01-11  9:12 ` Paolo Bonzini
@ 2007-01-11 13:56 ` John Love-Jensen
  2007-01-11 17:06 ` Mike Stump
  2 siblings, 0 replies; 4+ messages in thread
From: John Love-Jensen @ 2007-01-11 13:56 UTC (permalink / raw)
  To: Tathagato Rai Dastidar, MSX to GCC

Hi Tathagato,

[Removed gcc@gcc.gnu.org reply-to]

> Is there a way I can make GCC read a C or C++ code from the standard input
> instead of from a file?

Yes, definitely.  :-)

I do this (an Eljay original!), for example, to use GCC's preprocessor to
grep for Carbon API information:

carbon () 
{ 
  echo '#include <Carbon/Carbon.h>' \
  | g++ -H -x c++ -c -o /dev/null - 2>&1 \
  | sed -e 's/^[. ]*//' \
  | sort -u \
  | tr '\n' '\0' \
  | xargs -0 grep "$@"
}

Notice the g++ line?  I'm using the -x c++ to specify "interpret as C++",
and the - all by itself means "source comes from stdin".

I'm sending output to /dev/null, since I really just want the -H information
for this little quick-and-dirty Carbon grep'per.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Making gcc read from the standard input
  2007-01-11  6:31 Making gcc read from the standard input Tathagato Rai Dastidar
  2007-01-11  9:12 ` Paolo Bonzini
  2007-01-11 13:56 ` John Love-Jensen
@ 2007-01-11 17:06 ` Mike Stump
  2 siblings, 0 replies; 4+ messages in thread
From: Mike Stump @ 2007-01-11 17:06 UTC (permalink / raw)
  To: Tathagato Rai Dastidar; +Cc: gcc-help

On Jan 10, 2007, at 10:29 PM, Tathagato Rai Dastidar wrote:
> Is there a way I can make GCC read a C or C++ code from the  
> standard input instead of from a file?

$ echo 'int i;' | gcc -S -xc - -o -
.comm _i,16
         .subsections_via_symbols

Also, some systems have things like /dev/fd0 and /dev/stdin.  They  
are files that can be read, even if gcc didn't support the "-" filename.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-01-11 17:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-11  6:31 Making gcc read from the standard input Tathagato Rai Dastidar
2007-01-11  9:12 ` Paolo Bonzini
2007-01-11 13:56 ` John Love-Jensen
2007-01-11 17:06 ` Mike Stump

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).