This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: malloc attributes and realloc


Robert Dewar <dewar@gnat.com> writes:

| Gabriel Dos Reis wrote:
| 
| > | can be safely optimized into
| > |   *p = 'a';
| > That transformation caanot be applied for pointers returned by
| > realloc, in general.
| 
| Can you explain why?

The reason is obvious.

If p is a non-NULL pointer you get from a realloc, then it is
guaranteed that the content of object previously pointed-to is still
present at the start of new object.  Therefore, the compiler cannot,
in general, replace the test *p != 'a' by true.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]