Re: decrement past beginning is valid?
From: Watson Davis (watson_at_watsonmusic.com)
Date: 11/05/04
- Next message: Watson Davis: "Re: decrement past beginning is valid?"
- Previous message: Alwyn: "Re: (C) missing semi-colon"
- In reply to: David White: "Re: decrement past beginning is valid?"
- Next in thread: Karl Heinz Buchegger: "Re: decrement past beginning is valid?"
- Reply: Karl Heinz Buchegger: "Re: decrement past beginning is valid?"
- Reply: David White: "Re: decrement past beginning is valid?"
- Reply: Ron House: "Re: decrement past beginning is valid?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Nov 2004 07:55:17 GMT
"David White" <no@email.provided> wrote in
news:x8Bid.129$ob1.2005@nasal.pacific.net.au:
> "Watson Davis" <watson@watsonmusic.com> wrote in message
> news:Xns9597AC377962Athepencilneckyahooco@206.66.12.201...
>> "David White" <no@email.provided> wrote in
>> news:KExid.113$ob1.1782@nasal.pacific.net.au:
>>
>> > Hmmm. Suppose that on certain machines, including yet-to-be-built
>> > ones if necessary, an automatic pointer is stored in a CPU register
>> > intended specifically for holding a memory address, and suppose the
>> > mere act of storing it there generates an exception if it's an
>> > invalid address, which below the beginning of an array could be,
>> > then I suggest that it would be unwise to increment and decrement
>> > it all over the place.
>>
>> I'm not saying that it's an intelligent thing to do or that it won't
>> cause holy havoc. I'm just saying that it's legal from the
>> compiler's standpoint.
>
> What do you mean by 'legal'?
What I meant by legal is that a compiler will compile it.
>
> I refer to your earlier statement: "It's just a pointer and you can
> pretty much increment and decrement that thing all over the place
> without a problem". Did you mean that this is a guarantee imposed on
> all compilers by the language standard? If not, then what did you
> mean? Anything the standard does not guarantee is obviously not
> necessarily going to work on all conceivable platforms "without a
> problem".
Yes. That's pretty much what I meant. I was wrong in my understanding
that an array is the same as a pointer. In most cases it behaves the
same as a pointer, but it does have differences (that I was unaware of.)
BUT I would never, ever say that anything would work on "all conceivable
platforms." Ever. About anything. I don't care if it's the standard or
not. I've worked on too many different types of machines to believe
that.
Although subscripting out of the bounds of the array is undefined
behavior, the array reference is going to decay into pointer arithmetic
on MOST platforms. If you find yourself doing something like that, then
you're probably being too slick for your own good and you're probably
writing code that is totally not maintainable and should be taken out and
shot.
If you go back to the original poster's question, the code is obviously
being generated on a platform that supports negative subscripting because
the code is working with it.
Watson (the pencil neck) Davis
- Next message: Watson Davis: "Re: decrement past beginning is valid?"
- Previous message: Alwyn: "Re: (C) missing semi-colon"
- In reply to: David White: "Re: decrement past beginning is valid?"
- Next in thread: Karl Heinz Buchegger: "Re: decrement past beginning is valid?"
- Reply: Karl Heinz Buchegger: "Re: decrement past beginning is valid?"
- Reply: David White: "Re: decrement past beginning is valid?"
- Reply: Ron House: "Re: decrement past beginning is valid?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|