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.
@ saswat "puts" is in stdio.h library and I think you have to include that, otherwise you get compilation error!!
No, it would compile perfectly fine. Try it with your gcc : Code: main(){puts("Hello G4EF");} And, remember to compile as C not CPP. If it doesn't compile, post the screen-shots.
Perhaps I'm the only one who thinks this, but shouldn't it be Saswat that posts proof it works, rather than requiring other people to post proof that it doesn't?
Here is the error, what I get even with gcc compiler: /bnr/lb-tools/passport/cygnus/bin/gcc put.cc put.cc: In function `int main()': put.cc:3: warning: implicit declaration of function `int puts(...)' collect2: ld terminated with signal 11 [Segmentation Fault], core dumped As xp says, can you please post your code screen shot!! many thanks
Saving the file as cc means gcc will compile it as C++ not C. Save it as .c instead so that gcc will compile it as C instead.
But I think it's unfair that Saswat should win by posting code that obviously won't work (due to missing quotes) when others have posted longer code that would have worked.
Saswat can you please confirm on this because I think the code in post 23 and the one before is not same and the one in 23 would compile but not the one before it.
thanks XP for pointing out the mistake!! So, after moving the name to .c, I don't see that warning. but still get below error!! You have any idea? collect2: ld terminated with signal 11 [Segmentation Fault], core dumped many thanks in advance mridula
@ xpi0t0s :: Read what the conversation was all about b4 posting your view. Mridula and I were discussing about the 2nd program I posted, not the first one. I had mentioned that you don't need to #include <stdio.h> and Mridula says we must. -- THAT was the topic. And, I was requesting Mridula to post proof of that code. -------------- As I said earlier, the code I posted earlier (the one considered as the winning entry) would not compile on recent gcc compilers because of the "void main". The missing quotes was a typo. But even after adding missing quotes, the program won't work (as explained here). And so, I mentioned another shortest Hello G4EF code (which is still the shortest, if my previous entry is rejected.) Now here is the proof that it works :: I made a batch file with the following contents :: Code: PROMPT Time$S$Q$S$T$S$G$S TYPE hello.c mingw32-gcc -E hello.c mingw32-gcc hello.c -o test.exe test.exe pause The first line changes the DOS prompt to indicate the time to milli-second accuracy. (So that you would believe I haven't changed things in between.) The next line(2) prints the contents of hello.c. The next line(3) prints the contents of hello.c after pre-processing by MinGW. Finally the file is compiled to test.exe and it is executed. Now, here is the output : TEXT :: Code: D:\MinGW\bin>PROMPT Time$S$Q$S$T$S$G$S Time = 19:01:17.65 > TYPE hello.c main(){puts("Hello G4EF");} Time = 19:01:17.65 > mingw32-gcc -E hello.c # 1 "hello.c" # 1 "<built-in>" # 1 "<command line>" # 1 "hello.c" main(){puts("Hello G4EF");} Time = 19:01:17.68 > mingw32-gcc hello.c -o test.exe Time = 19:01:17.82 > test.exe Hello G4EF Time = 19:01:17.84 > pause Press any key to continue . . . SCREEN-SHOT :: @ Mridula : I don't know why it gives that error on linux system. Look at the screen-shots I gave above (done in Windows XP SP3). May be linux gives that error 'cuz of the missing return 0. Can you plz test this then : Code: main(){puts("Hello G4EF"); return 0;} I hope this satisfies everyone. BTW, I had mentioned in my very first entry that I have "NOT" tested the code. So, if I was declared the winner, it's not my fault and btw, now I have proved that I have come up with the shortest code (Guess that's fair enough)