tl;dr they all use - as input file to indicate standard input:


clang -x<lang> [-std=<standard>] -o <outfile> -
cpp [-x<lang>] [-std=<standard>] -o <outfile> -
gcc [-x<lang>] [-std=<standard>] -o <outfile> -
g++ [-x<lang>] [-std=<standard>] -o <outfile> -
tcc -o <outfile> -

Warning

I am not an adequate coder of C or C++, any information or thoughts provided here could have flaws. Please don’t hesitate to point out my mistakes.

On Gentoo Linux with these versions:

  • Clang 3.5.0 (2014-09-05)
  • GCC 4.8.4 (2014-12-19)
  • TCC 0.9.26 (2013-02-15)

1   GCC (GNU Compiler Collection)

By default, GCC treats standard input source as C, even directly using g++, therefore if the code is C++ and -std=<standard> is used, you will need to specify the language using -xc++, or you will get a warning like:


% cpp -std=c++98 - </dev/null
cc1: warning: command line option '-std=c++98' is valid for C++/ObjC++ but not for C [enabled by default]

I also list cpp (The C Preprocessor), because it accepts the standard input in the same way as gcc and g++ do. In fact, I learned about this for finding macro definition location, primarily the predefined macros.

2   TCC (Tiny C Compiler)

Beside the example in the beginning, you can directly run the compiled program without writing to a file,


tcc -run -