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: PR 25512: pointer overflow defined?


Robert Dewar <dewar@adacore.com> writes:

| Gabriel Dos Reis wrote:
| 
| >you can (equality) compare a pointer to NULL -- which does not even
| >happen to designate an object.
| >
| Well accurately, you can compare pointers, its not illegal, but the
| result of
| comparing pointers to separately allocated objects is undefined.

Well, that is not what the C standard says. E.g., the exact wording is
more convoluted and given the wording for what is "object" in the C
standard

       3.14
       [#1] object
       region of data storage in  the  execution  environment,  the
       contents of which can represent values

with no more qualifications (this definition is slightly different in
some nearby languages), it is slippery to found optimizations on
"pointer overflows."

And even more so, the existing practice in widely used programs is to
compare pointers to things like (void *)-1.  And this even in GCC own
source code.

-- Gaby


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