Quote:
Originally Posted by xpi0t0s View Post
I think it won't work because there are missing quotes:
Code:
puts(Hello, World!)
Apart from that though the principle of putting one character in the C file and using a -D to place the code is absolutely fine, in fact this is what one of the IOCCC winners did (although his file was 3 characters long: A;<eof>).
Yeah, I saw that IOCCC winning entry too.

But, even if we add the quotes around "Hello, World!", I don't think it would work.
I don't think the idea of macro-ing the single char 'A' is alright, because the macro definition -DA=__FILE__ will cause A to be replaced by "void main(){puts("Hello, World!");}c.c"(** with the quotes **). Further due to the quotes, the macro -Dc=// becomes useless ! Because the compiler recognizes the whole program as one string, so does not replace the "c.c" at the end by "//.//".
So, the program after pre-processing only (check that with -E flag) will look like :
Code:
"void main(){puts("Hello, World!");}c.c"
which will cause the compiler to trigger a string definition error or something like that because of the quotes in the program.

I don't know if the way behavior of __FILE__ has been changed in recent gcc versions. May be earlier they didn't contain the quotes around the file-name.