gcc input files

John (Eljay) Love-Jensen eljay@adobe.com
Wed Mar 18 12:02:00 GMT 2009


Hi Silverio,

> I would like to know if is possible use pipe to pass
> gcc input files instead use an actual file, eg:
> 
> cat test.c | gcc -s

Yes.  Here's how I do it:

cat foo.c | grunge | twizzle | gcc -x c - -o foo.o

Where, for example, grunge and twizzle being two custom preprocessors.  The
grunge filter acts much like the standard C preprocessor, and twizzle filter
acts much like the Objective-Whatnot preprocessor.

Here's another bash shell example...

carbongrep ()
{
 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 "$@"
}

The upshot of carbongrep is that it allows you to grep through all the
Carbon header files for some identifier.

Here's yet another example, which tells you which optimization flags are
enabled by a given optimization level, here using bash's process
substitution named pipe:

gcc -fverbose-asm -H -x c <(echo '') -O1 -S -o O1.s

HTH,
--Eljay



More information about the Gcc-help mailing list