Re: Undefined behavior or not?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/12/17 02:14, Andrew Makhorin wrote:
>> No, that is not how it works.  6.2.4/2 says: [...] "The value of a
>> pointer becomes indeterminate when the object it points to (or just
>> past) reaches the end of its lifetime."
>>
>> It does not matter whether the value of p changes in *your* system,
>> or in most systems.  Using the value of p after deallocating the object
>> it pointed to is undefined behaviour.
>>
>
> Does this mean that the following fragment is invalid? (I think it
> isn't.)
>
>    void *p, *q;
>    p = malloc(123);
>    q = p;
>    free(p);
>    if (p == q) ...
>
> Thanks.
>

Yes, as well as this:

   char *p, *q;
   p = malloc(123);
   q = p + 123;
   free(p);
   if (q == p + 123) ...


Bernd.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux