Bug in loop optimize (invalid postinc to preinc transformation)

dewar@gnat.com dewar@gnat.com
Sun Dec 31 08:30:00 GMT 2000


<<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 :-)


More information about the Gcc mailing list