clinuxgcc

question on c compilation


On a linux box

is it compulsory to write a program into a file and compile it

cant this be done from command line

localhost$gcc "include<stdio.h> int main(){printf('hello world'); return o; }"

Solution

  • sure you can, but i doubt that that makes sense....

    $ echo '#include <stdio.h>
    int main() { printf("hello world\n"); return 0; }' | gcc -x c -
    $ ./a.out 
    hello world
    $
    

    gcc options:

      -o <file>                Place the output into <file>
      -x <language>            Specify the language of the following input files
                               Permissible languages include: c c++ assembler none
                               'none' means revert to the default behavior of
                               guessing the language based on the file's extension