Page 2 of 2
Re: obfuscated C code
Posted: 11 Jun 2011, 22:29
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.
Re: obfuscated C code
Posted: 11 Jun 2011, 22:33
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).
Re: obfuscated C code
Posted: 12 Jun 2011, 00:55
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.