What every C Programmer should know about undefined behavior
Posted May 16, 2011 16:37 UTC (Mon) by
cfischer (subscriber, #3983)
In reply to:
What every C Programmer should know about undefined behavior #2/3 by gowen
Parent article:
What every C Programmer should know about undefined behavior #2/3
Why not just say:
void contains_null_check(int *P) {
int dead;
if (P == 0)
return;
dead = *P;
/* do with 'dead' whatever you want */
}
Wouldn't that be the more 'natural' C style?
Methinks, the
int dead = *P;
in the example is a misguided result of the urge to 'initialize',
as opposed to 'assign'. In C++ those might be different, but in
old-style C, for simple datatypes, avoiding the assignment for
such reasons could already be seen as bad influence by new-fangled
object-oriented hip languages.
So the problem seems more one of mixing styles to me.
(
Log in to post comments)