This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Making gcc read from the standard input
- From: John Love-Jensen <eljay at adobe dot com>
- To: Tathagato Rai Dastidar <Tathagato dot Rai dot Dastidar at nsc dot com>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Thu, 11 Jan 2007 07:56:15 -0600
- Subject: Re: Making gcc read from the standard input
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