This is the mail archive of the gcc-patches@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: PR3609


On Thu, Aug 09, 2001 at 06:14:51PM -0400, Jakub Jelinek wrote:
> On Thu, Aug 09, 2001 at 03:06:19PM -0700, Mark Mitchell wrote:
> > 
> > > 	You are referencing beyond the end of an object.  That's undefined
> > > behavior.
> > 
> > Yes, I know that rule.
> > 
> > But, this is slightly subtle.
> > 
> > Surely, you would not argue that:
> > 
> >   ((size_t)"foo") + 10
> > 
> > has undefined behavior?  The cast is OK, if a size_t is wide enough.
> > And adding 10 to a size_t is OK.
> > 
> > And, casting the size_t back to a pointer is OK, too -- but
> > implementation-defined.
> 
> But in *(char *)(((size_t)"foo") + 10) you are referencing beyond the end of
> object, so IMHO ((size_t)"foo") + 10 is fine, but *(char *)(((size_t)"foo") + 10)
> has undefined behaviour.
> And strlen references the characters at that location.

But we're not trying to reference "that object" any more - which should
be clear from the fact that we're pointing outside it!  We're trying to
reference something at a known offset from the beginning of that
object, and we do know (precisely and correctly) what that offset is. 
I think that this is perfectly reasonable, if you're operating in a
situation where you can know that offset.

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


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