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


Gabriel Dos Reis wrote:

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.

Why not? the fact of the matter is that the semantics of the code fragment are identical whether or not the test is true or false, so there is no need to do the test.

The semantics of a sequence of C statements is defined by its final
effect, the operational definition of how this effect might be achieved
does not prohibit the same effect being obtained by different means (that is what optimization is about!).


For example, a C compiler clever enough to turn a bubble sort into
a logically equivalent heap sort is free to do so!



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