[OT]C CO tim chtel basnik rici?

Jan Waclawek konfera na efton.sk
Středa Prosinec 31 10:42:34 CET 2014


>Jak je to s nasledujicim zapisem - je podle normy OK nebo funguje jen 
>nahodou (ja to radsi nepouzivam ale casto to vidim)
>
>char *str;
>...
>if (str != NULL && str[0] != 0)
>...
>
>Problem muze byt IMHO v poradi vyhodnoceni, pokud by str bylo NULL a 
>vyhodnocovalo se nejdriv str[0], dojde k memory fault. I kdyz evidentne 
>to obecne funguje a pouziva se to.



C99, 6.5.13#4
Unlike the bitwise binary & operator, the && operator guarantees
left-to-right evaluation;
there is a sequence point after the evaluation of the first operand. If the
first operand
compares equal to 0, the second operand is not evaluated.


wek



Další informace o konferenci Hw-list