As the title says..I know C++/Java do IIRC, but does C?
ie. safe practice?
Code:if (!my_struct || !my_struct->my_ptr);
As the title says..I know C++/Java do IIRC, but does C?
ie. safe practice?
Code:if (!my_struct || !my_struct->my_ptr);
Safe... but not guaranteed to shortcircuit, far as I know...
How would it be not guaranteed but still safe? If 'my_struct' is a pointer, and short circuiting isn't guaranteed, then there's a chance of dereferencing a NULL pointer.
You're saying that it's only guaranteed for logical AND? Hrm, interesting. Seeing as a logical OR doesn't require both sides to be evaluated in terms of boolean logic, I'm surprised it needs to be by the compiler.
If you want to look it up yourself check out 6.5.14.4 for OR and 6.5.13.5 for AND in C99. It will be around there, I only have one of the draft versions.
Ha, I'll take your word for it .
I have to get around to reading the whole draft spec when I get some free time - I'll save it until then ^_^.
Besides, only half the battle is it being in the draft spec, the other part is the (possibly bad) assumption that what you're using is 100% compliant with the C-spec, lol.
Also, this is C89 IIRC.
Guaranteed short-circuiting of logical expressions has always been a feature of C. It was true when Dennis Ritchie designed and implemented the first version of C, still true in the 1989 C standard, and remains true in the C99 standard.