|
|
On 23/07/2011 06:13 PM, Darren New wrote:
> On 7/23/2011 7:59, Warp wrote:
>> If you access first and check bounds afterwards, that's kind of a bit
>> late, don't you think?
>
> In the first example, he reads, then checks, then writes, and it's not
> unreasonable to think that he's ensuring the write isn't out of bounds
> because the read is harmless. (Yes, there are still architectures where
> *NULL does not trap.)
More to the point, according to the C spec, NULL is not /required/ to
trap. Ever. The compiler is 100% free to make it do whatever it likes.
Which isn't especially surprising. The surprising thing is that you've
got code there explicitly to check for a null pointer, and the optimiser
may or may not end up removing it for you.
Post a reply to this message
|
|