This is the mail archive of the
mailing list for the GCC project.
Re: gcc for syntax check only (C): need to read source from stdin
- From: Devang Patel <dpatel at apple dot com>
- To: Dimitry Golubovsky <golubovsky at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 12 Apr 2005 09:04:52 -0700
- Subject: Re: gcc for syntax check only (C): need to read source from stdin
- References: <email@example.com>
To read source from stdin use "-".
preprocessor man page says,
Either infile or outfile may be -, which as infile means to
standard input and as outfile means to write to standard output.
On Apr 12, 2005, at 7:10 AM, Dimitry Golubovsky wrote:
A program I am working on generates some C code on the fly, and I
would like to check its syntax right after generation. I might save
this code fragment in a temporary file and gun gcc -c over it,
watching for exit code (0: syntax OK, 1: incorrect). This is fine with
the one exception that I have to create temporary files and then clean
them up. Does there exist any way to accompilsh this with pipes
entirely? Output object file may be discarded: I don't need it. Or I
might even use -S option to only assemble, but again, output must be
stdout, not a file (or /dev/null which does not work either: the last
program in the pipeline tries to CREATE it, not to write into it, and
Looking for verbose output from gcc -v -pipe ... I noticed that all
the components (cpp, cc1, as) are pipe-connectable (at least in most
cases). It is only the gcc (driver) which says e. g.
gcc: -E required when input is from standard input
which limits me to using preprocessor as a pipe only.
I am afraid direct invocation of cc1 may not be good because I have no
idea how its command line options are stable across various versions
Does there exist an alternative driver/script doing same job as the
"stock" gcc, but allowing piping its input and output?
Anywhere on the Web