obfuscated C code

Discuss anything and everything. Keep it clean (or else).
bullestock
Posts: 27
Joined: 29 Sep 2010, 19:34
Location: Denmark
Contact:

Re: obfuscated C code

Post by bullestock »

doc-helmut wrote:
hergipotter wrote:
muntoo wrote: Also, I'm not sure, but won't the right side of the || operator not be evaluated, if the left side is true? (There's no further need to evaluate the right side, if the first one is already true.)
yes, that's it. At least it's true for some other languages, i'm not 100% sure for C...
I won't bet, maybe it's a compiler optimization option....
No, the C standard defines this behaviour. It is known as short-circuit evaluation.
bullestock
Posts: 27
Joined: 29 Sep 2010, 19:34
Location: Denmark
Contact:

Re: obfuscated C code

Post by bullestock »

hergipotter wrote:First, F is decremented, then it is checked if it's positive. If yes, then the second statement is not processed because of the OR operator. If not, then OO is decremented and is substracted from F. I have to admit that i don't really know what the substraction is for...
The subtraction is irrelevant, as it has no side effect (unlike the decrement). I am pretty sure it was only put in to get a nice visual effect (and make the code look more complicated).
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: obfuscated C code

Post by muntoo »

doc-helmut wrote:and what's the advantage to use size_t instead of simply (and explicitely) int or char or long?
I saw it here. Apparently, it's 'more portable'.

@bullestock I knew something like that was in the standards (heard it at StackOverflow), but I couldn't remember what it was called.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest