Re: Out-of-bounds nonsense
- From: "Old Wolf" <oldwolf@xxxxxxxxxxxxxx>
- Date: 1 Nov 2006 20:38:44 -0800
Frederick Gotham wrote:
Andrey Tarasevich:
Also it is worth noting that the big intuitive problem with this kind of
access being illegal is that the "ranged-pointer" feature I described
above is definitely out of place in C.
Yes. I like control. I _love_ control. That's why I opt for _proper_
programming languages like C and C++, and not mickey-mouse
languages like Java.
What is mickey-mouse about Java ?
Also it is worth noting that the big intuitive problem with this kind of access
being illegal is that the "ranged-pointer" feature I described above is
definitely out of place in C. In stronger words, an artificial restriction like
this is completely unacceptable in C. Moreover, it is completely unacceptable in
C++ as well It is something a 'std::vector<>' might do, but not a raw pointer).
And, as one would expect in case of such a random restriction, there's no
rationale behind it at all.
I, for one, would find such a pointer very useful for debugging.
Currently my compiler includes a tool that will warn when I
step outside the bounds of an allocated block of memory.
But that won't help with code like:
struct S {
int x[4];
int y[4];
};
struct S s;
if I accidentally access s.x[5] . Which, I should add, I would
consider a bug (some of you would consider it a feature,
apparently).
So how do we get our hands on a "Range-liberal pointer", a pointer without
armbands? Must we have an intermediate cast to something like a void* or a
char* in order to liberate the pointer from its range restriction?
No, casts don't affect the pointer range. What do you mean by
"range-liberal pointer" ? The C standard is quite clear that you
cannot portably point outside the bounds of an object. The only
thing we are debating here is whether it is OK if the pointer
leaves the bounds of the object it was pointing to, but it is
still within the bounds of an object of which the original object
were a sub-object.
It is not a part of C that you can use pointer arithmetic on
a pointer to move it around any part of some flat address
space you might imagine.
int *const p = (int*)(char unsigned*)&arr;
The second cast is unnecessary; the expression "&arr" implies
a range of anywhere inside the object designated by "arr",
(and one-after-the-end of course).
.
- References:
- Out-of-bounds nonsense
- From: Frederick Gotham
- Re: Out-of-bounds nonsense
- From: Andrey Tarasevich
- Re: Out-of-bounds nonsense
- From: Frederick Gotham
- Out-of-bounds nonsense
- Prev by Date: Re: string search?
- Next by Date: Re: Long Num speed
- Previous by thread: Re: Out-of-bounds nonsense
- Next by thread: Re: Out-of-bounds nonsense
- Index(es):
Relevant Pages
|