Undefined behavior or not?

Segher Boessenkool segher@kernel.crashing.org
Fri Mar 10 16:12:00 GMT 2017


On Fri, Mar 10, 2017 at 11:57:28PM +0800, Liu Hao wrote:
> >So does this mean, that the above C code uses undefined behavior?
> Yes.
> 
> 6.2.4 Storage durations of objects
> 1 ... Allocated storage is described in 7.22.3.
> 2 ... The value of a pointer becomes indeterminate when the object it 
> points to (or just past) reaches the end of its lifetime.
> 
> 7.22.3 Memory management functions
> 1 ... The lifetime of an allocated object extends from the allocation 
> until the deallocation. ...

But a null pointer does not point to an (allocated) object.  So the
code has undefined behaviour only if ever the pointer is not a null
pointer?

What a mess :-)


Segher



More information about the Gcc-help mailing list