hey C[++] gurus! What does this code do...

Started by Darren Dirt, May 23, 2012, 12:51:05 PM

Previous topic - Next topic

Darren Dirt

_____________________

Strive for progress. Not perfection.
_____________________

Lazybones

Quote from: Darren Dirt on May 23, 2012, 12:51:05 PM
found via http://stackoverflow.com/questions/235848/most-astonishing-violation-of-the-principle-of-least-astonishment

QuoteThis question was removed from Stack Overflow for reasons of moderation. Please refer to the FAQ for possible explanations why a question might be removed.

Thorin

At first glance I thought I understood it.
At second glance, it looked a little complicated.
At third glance, MADNESS
Prayin' for a 20!

gcc thorin.c -pedantic -o Thorin
compile successful

Mr. Analog

Check the accepted answer: http://meta.stackoverflow.com/questions/27112/amusing-404-page-not-found-images-for-trilogy-sites

AND the comment (explains why this is on the 404 page for Stack Overflow) :D

EDIT: (hint: HTTP 404)
By Grabthar's Hammer

Thorin

Ah yes, those aren't #defines, as there's incorrect spacing in all three of them.  They're just all commented out (as is line 3).
Prayin' for a 20!

gcc thorin.c -pedantic -o Thorin
compile successful

Tom

Quote from: Thorin on May 23, 2012, 01:54:01 PM
Ah yes, those aren't #defines, as there's incorrect spacing in all three of them.  They're just all commented out (as is line 3).
Nope. You're allowed to have spaces before the command with the C preprocessor. So long as the text that follows is a cpp command. Otherwise it is just a comment of sorts.
<Zapata Prime> I smell Stanley... And he smells good!!!

Thorin

#<space>define
#<space><space><space>define

are not valid because there's a space between the # and "define".

#define/*>.@*/exit()

is not valid because there's no identifier

I'm not saying this won't compile, I'm saying lines 1, 2, 3, and 5 have no impact on what this code does.
Prayin' for a 20!

gcc thorin.c -pedantic -o Thorin
compile successful

Mr. Analog

Did anyone actually follow this link: http://meta.stackoverflow.com/a/27846

'cause seriously Perl/Python/Ruby/C/Befunge/BF

NOT C++
By Grabthar's Hammer

Tom

Quote from: Thorin on May 23, 2012, 02:22:54 PM
#<space>define
#<space><space><space>define

are not valid because there's a space between the # and "define".

#define/*>.@*/exit()

is not valid because there's no identifier

I'm not saying this won't compile, I'm saying lines 1, 2, 3, and 5 have no impact on what this code does.
Again, not true. You can have spaces between the # and the command name. It's 100% valid at least on GCC, and I assume VC++ as well.

Quote from: Mr. Analog on May 23, 2012, 02:29:52 PM
Did anyone actually follow this link: http://meta.stackoverflow.com/a/27846

'cause seriously Perl/Python/Ruby/C/Befunge/BF

NOT C++
C++ is mostly a superset of C. So in this case, same difference. Both use the same preprocessor.
<Zapata Prime> I smell Stanley... And he smells good!!!

Mr. Analog

True, but I reckon Thorin is used to seeing MS Visual C++ not console C++

anywhoo FOLLOW DA LIMK

By Grabthar's Hammer

Tom

Quote from: Mr. Analog on May 23, 2012, 02:43:39 PM
True, but I reckon Thorin is used to seeing MS Visual C++ not console C++

anywhoo FOLLOW DA LIMK


I did ;)
<Zapata Prime> I smell Stanley... And he smells good!!!

Mr. Analog

cool cool :D

Also I just tried running this in C++ and got a compile error, but it went like bananas in C, and I got the expected output :D
By Grabthar's Hammer

Tom

Quote from: Mr. Analog on May 23, 2012, 02:51:24 PM
cool cool :D

Also I just tried running this in C++ and got a compile error, but it went like bananas in C, and I got the expected output :D
Yeah, C++ probably doesn't like the lack of "int" before main, and the lack of parameters in main as well. () in C++ is the same as (void) in C. () in C is "unspecified" meaning it can take any number of parameters.
<Zapata Prime> I smell Stanley... And he smells good!!!

Mr. Analog

Yep, t'was a trip down memory lane... I haven't touched C++ in a while...

Also, best 404 message EVAR
By Grabthar's Hammer

Lazybones

Just for fun (since I don't have have a c compiler installed)

http://codepad.org/e1L959z5