This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]