Paolo Bonzini wrote:
> Tathagato Rai Dastidar wrote:
>> Hello,
>>
>> Is there a way I can make GCC read a C or C++ code from the standard
>> input instead of from a file?
>>
>> In my application software, I am generating some C code on the fly,
>> writing it to a file, then using GCC to compile it. Instead of that, I
>> want to invoke GCC through a pipe, and write the C code directly into
>> GCC, instead of writing it into a file and then calling GCC.
>>
>> Is this possible?
> 
> This is a question only for gcc-help.  Cross-posting gcc and gcc-help is
> almost always wrong.  :-) But yes, it is possible by adding "-x c" to
> the command line, so that the gcc driver knows which front-end to
> invoke.  In the case of "-E", in fact, GCC implicitly considers the
> language to be C (and invokes the C front-end) because the preprocessor
> is the same for all input languages; but for real compilation, you need
> to specify the language manually.

The preprocessor shouldn't be the same for all languages;
there are differences between C90, C++98 and C99 in a number
of aspects (predefined macros, interpretation of true in
expressions, vararg macro support, presence of alternate
tokens in C++, support for long long values and probably
more than slip my mind right now).  Some of the differences
can be ignored because they fall into the realms of defining
undefined behaviours, but others have well-defined but
differing behaviour depending on the language.

-- James

Reply via email to