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

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

Previous topic - Next topic

Thorin

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.
Prayin' for a 20!

gcc thorin.c -pedantic -o Thorin
compile successful

Mr. Analog

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)
By Grabthar's Hammer

Thorin

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 :)
Prayin' for a 20!

gcc thorin.c -pedantic -o Thorin
compile successful

Lazybones


Mr. Analog

Well, now I know Thorin reads my posts all the way through LOL
By Grabthar's Hammer

Darren Dirt

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.

_____________________

Strive for progress. Not perfection.
_____________________

Lazybones

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.

Mr. Analog

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.

;)
By Grabthar's Hammer

Darren Dirt

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
_____________________

Strive for progress. Not perfection.
_____________________

Thorin

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.
Prayin' for a 20!

gcc thorin.c -pedantic -o Thorin
compile successful

Mr. Analog

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.

By Grabthar's Hammer