tags:

views:

207

answers:

2

Just came across this guy that left me stunned:

gcc -E -dM - </dev/null

This part is confusing to me:

 - </dev/null
+10  A: 

That gives a listing of all the predefined macros in gcc. -E means run the preprocessor. -dM means dump the predefined macros from the preprocessor. The - is for reading from standard input and /dev/null just feeds in an empty source file.

karunski
+2  A: 

The "</dev/null" bit is at the shell level and not specific to gcc

< defines input file
> defines ouput file for std out, 
>> defines a output for std out that will be appended to,
| sends std out output to another process on it's std in

I forget the syntax but you can also specify std err aswell like &2>

The name after the brackets is the name of a file, where /dev/null is an empty file

man sh should get you to the right sort of help for these questions.

Don't have access to gcc at the moment, assuming from other comment that - is reading from std in, then and equivelant statement is

gcc -E -dM /dev/null
Greg Domjan
This doesn't work because GCC looks at the filename `/dev/null`, and says "doesn't have a `.c` extension, so I won't preprocess it".
ephemient
@ ephemient: No. /dev/null is a special device that acts like a file and it is not being read as a file. The < means pass the following to the standards input. The - means read the standard input instead of a file.
Martin York
@Martin: I'm talking about the end of Greg's answer, regarding the command `gcc -E -dM /dev/null`: that doesn't work. If you don't let GCC know the filename, using `gcc -E -dM - </dev/null`, or force C source, using `gcc -E -dM -x c /dev/null`, of course it works.
ephemient
I wonder what `/dev/null` actually does when read. I thought it cannot be read. But it seems like it can, but it just will signal EOF always and size 0?
Johannes Schaub - litb
@litb: http://linux.die.net/man/4/null `read` always returns 0, `write` always succeeds (with no effect).
ephemient