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]

Re: Bug in loop optimize (invalid postinc to preinc transformation)


<<Comparing pointers that don't point to the same (part of) object is
undefined.
>>

Indeed. The important thing to remember in C is that the semantic
model of a pointer is a pair (pointer-to-object, offset). Address
arithmetic just modifies the offset, comparison compares only the
offsets (and is undefined if the pointer-to-object values are
different).

Of course in practice the implementation is typically a single pointer
from a flat space, representing the sum of the two components, but the
proper semantic model needs to be kept in mind, and code that does not
respect this semantic model has undefined effects.

As C compilers get more clever, they are likely to be less permissive
to abuses of the semantics :-)

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