1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Shortest Hello G4EF | 8 Sep 2009

Discussion in '$1 Daily Competition' started by shabbir, Sep 8, 2009.

  1. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    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.
     
  2. Mridula

    Mridula New Member

    @ saswat

    "puts" is in stdio.h library and I think you have to include that, otherwise you get compilation error!!
     
  3. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    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.
     
  4. xpi0t0s

    xpi0t0s Mentor

    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?
     
  5. Mridula

    Mridula New Member

    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
     
  6. xpi0t0s

    xpi0t0s Mentor

    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.
     
  7. xpi0t0s

    xpi0t0s Mentor

    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.
     
  8. shabbir

    shabbir Administrator Staff Member

    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.
     
  9. Mridula

    Mridula New Member

    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
     
  10. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    @ 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 ::

    [​IMG]


    @ 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)
     

Share This Page