Righteous Wrath Online Community

General => Lobby => Topic started by: Darren Dirt on May 23, 2012, 12:51:05 PM

Title: hey C[++] gurus! What does this code do...
Post by: Darren Dirt on May 23, 2012, 12:51:05 PM
(http://sstatic.net/stackoverflow/img/polyglot-404.png)

the "#define" is where stuff gets real.


found via http://stackoverflow.com/questions/235848/most-astonishing-violation-of-the-principle-of-least-astonishment

Title: Re: hey C[++] gurus! What does this code do...
Post by: Lazybones on May 23, 2012, 12:55:29 PM
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.
Title: Re: hey C[++] gurus! What does this code do...
Post by: Thorin on May 23, 2012, 01:26:29 PM
At first glance I thought I understood it.
At second glance, it looked a little complicated.
At third glance, MADNESS
Title: Re: hey C[++] gurus! What does this code do...
Post by: Mr. Analog on May 23, 2012, 01:32:45 PM
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)
Title: Re: hey C[++] gurus! What does this code do...
Post by: 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).
Title: Re: hey C[++] gurus! What does this code do...
Post by: Tom on May 23, 2012, 01:55:24 PM
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.
Title: Re: hey C[++] gurus! What does this code do...
Post by: 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.
Title: Re: hey C[++] gurus! What does this code do...
Post by: 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++
Title: Re: hey C[++] gurus! What does this code do...
Post by: Tom on May 23, 2012, 02:39:59 PM
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.
Title: Re: hey C[++] gurus! What does this code do...
Post by: 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

(http://i.imgur.com/PjkPz.jpg)
Title: Re: hey C[++] gurus! What does this code do...
Post by: Tom on May 23, 2012, 02:46:02 PM
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

(http://i.imgur.com/PjkPz.jpg)
I did ;)
Title: Re: hey C[++] gurus! What does this code do...
Post by: 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
Title: Re: hey C[++] gurus! What does this code do...
Post by: Tom on May 23, 2012, 02:54:24 PM
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.
Title: Re: hey C[++] gurus! What does this code do...
Post by: Mr. Analog on May 23, 2012, 02:57:16 PM
Yep, t'was a trip down memory lane... I haven't touched C++ in a while...

Also, best 404 message EVAR
Title: Re: hey C[++] gurus! What does this code do...
Post by: Lazybones on May 23, 2012, 03:03:18 PM
Just for fun (since I don't have have a c compiler installed)

http://codepad.org/e1L959z5
Title: Re: hey C[++] gurus! What does this code do...
Post by: Thorin on May 23, 2012, 03:12:29 PM
I clicked through the first link you posted and read the accepted answer (and a bunch of others,  interesting topic).  I've also now clicked through your second link, not realizing it was the accepted answer.

I don't believe I said anything about C++?

Also

Quote from: Tom on May 23, 2012, 02:39:59 PM
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.

if that is true then I learned something new today.

Every C (not C++) reference I read for preprocessor directives in the last 15 minutes says nothing about allowing spaces between # and define, neither whether it is allowed or not.
Title: Re: hey C[++] gurus! What does this code do...
Post by: Mr. Analog on May 23, 2012, 03:16:23 PM
Well I assumed you were talking about C++ because very often when you see stuff defined there's no space "#define blah" you mentioned the space so I jumped to conclusions (on my special Jump to Conclusions Mat)
Title: Re: hey C[++] gurus! What does this code do...
Post by: Thorin on May 23, 2012, 03:22:25 PM
Nice Lazy.  So in C the #defines are accepted and used, in Perl they're simply commented out.

Had to look up putchar (http://www.cplusplus.com/reference/clibrary/cstdio/putchar/) and then ASCII codes (http://ascii.cl/htmlcodes.htm) to see what those first two #defines do.

Still.  Barn.  Behind.  Beaten.

And I should borrow that mat of your sometime, I do it to :)
Title: Re: hey C[++] gurus! What does this code do...
Post by: Lazybones on May 23, 2012, 03:28:05 PM
Quote from: Thorin on May 23, 2012, 03:22:25 PM
And I should borrow that mat of your sometime, I do it to :)

???
Title: Re: hey C[++] gurus! What does this code do...
Post by: Mr. Analog on May 23, 2012, 03:36:44 PM
Well, now I know Thorin reads my posts all the way through LOL
Title: Re: hey C[++] gurus! What does this code do...
Post by: Darren Dirt on May 23, 2012, 03:38:16 PM
So I didn't read the SO comments/discussion, but I did visit the http://codepad.org/ link and saw the output.

Whoever offered that as a suggestion for the 404 for the above-average-intelligence community of Stack Overflow: Way to make the over-thinkers of the world feel pretty dumb. Well played.

Title: Re: hey C[++] gurus! What does this code do...
Post by: Lazybones on May 23, 2012, 03:38:52 PM
Quote from: Mr. Analog on May 23, 2012, 03:36:44 PM
Well, now I know Thorin reads my posts all the way through LOL

Ok, I get it now.
Title: Re: hey C[++] gurus! What does this code do...
Post by: Mr. Analog on May 23, 2012, 03:40:02 PM
Quote from: Darren Dirt on May 23, 2012, 03:38:16 PM
So I didn't read the SO comments/discussion, but I did visit the http://codepad.org/ link and saw the output.

Whoever offered that as a suggestion for the 404 for the above-average-intelligence community of Stack Overflow: Way to make the over-thinkers of the world feel pretty dumb. Well played.

Yeah but think about all the laughs shared by programmers :D (and try not to think of the furrowed brows of the non-programmers)

Quote from: Lazybones on May 23, 2012, 03:38:52 PMOk, I get it now.

;)
Title: Re: hey C[++] gurus! What does this code do...
Post by: Darren Dirt on May 23, 2012, 03:41:07 PM
Also, it *appears* "polyglot" which in theory means the output for C is the output for Perl or Python or whatever the other language is -- although it might depend on compilers or whatnot, although now it's clear the intention is to be the same "destination", just gets there via a different "route".

http://en.wikipedia.org/wiki/Polyglot_%28computing%29
Title: Re: hey C[++] gurus! What does this code do...
Post by: Thorin on May 23, 2012, 03:58:46 PM
Quote from: Mr. Analog on May 23, 2012, 03:36:44 PM
Well, now I know Thorin reads my posts all the way through LOL

Yes I do.  I'm compelled to.  Not fully reading a post feels ... wrong.

What OCD?

Anyway, my first introduction to the word "polyglot" was as a kid when I was reading the OD&D Masters ruleset and they were talking about the different paths to demigodhood.  It feels weird using that word to describe a bunch of text interpreted as code for multiple compilers.
Title: Re: hey C[++] gurus! What does this code do...
Post by: Mr. Analog on May 23, 2012, 04:05:25 PM
Funny you mention that I was thinking about the first time I found out that all Palladium RPGs were compatible with each other with some minor tweaking.

(http://i.imgur.com/pdLzs.gif)