Re: Making gcc read from the standard input

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Tathagato,

[Removed gcc@xxxxxxxxxxx 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux