D - Bug: Properties of pointers
- Russell Lewis <spamhole-2001-07-16 deming-os.org> Sep 11 2002
- Russell Lewis <spamhole-2001-07-16 deming-os.org> Sep 11 2002
- "Walter" <walter digitalmars.com> Sep 12 2002
- Pavel Minayev <evilone omen.ru> Sep 12 2002
- "Walter" <walter digitalmars.com> Sep 12 2002
- "Sean L. Palmer" <seanpalmer earthlink.net> Sep 13 2002
- "Walter" <walter digitalmars.com> Sep 13 2002
I tried this:
struct asdf { uint thing1; uint thing2; uint thing3; uint thing4; };
asdf foo;
asdf* bar;
assert(foo.size == 16); // works
assert((*bar).size == 16); // works
assert(bar.size == 4); // fails!!!
It says it fails with "16 == 4", which tells me that when I do bar.size,
I'm getting the size of the structure underlying the pointer, NOT the
pointer itself. However, if I declare a pointer-to-pointer, I get a
size of 4:
asdf** fred;
assert(fred.size == 4); // works
So first of all, does the property of a pointer refer to the pointer, or
to the thing it points to? If the former, then how do we get info about
the pointer? If the latter, then shouldn't it recurse down through all
pointers?
Sep 11 2002
Russell Lewis wrote:I tried this: struct asdf { uint thing1; uint thing2; uint thing3; uint thing4; }; asdf foo; asdf* bar; assert(foo.size == 16); // works assert((*bar).size == 16); // works assert(bar.size == 4); // fails!!! It says it fails with "16 == 4", which tells me that when I do bar.size, I'm getting the size of the structure underlying the pointer, NOT the pointer itself. However, if I declare a pointer-to-pointer, I get a size of 4: asdf** fred; assert(fred.size == 4); // works So first of all, does the property of a pointer refer to the pointer, or to the thing it points to? If the former, then how do we get info about the pointer? If the latter, then shouldn't it recurse down through all pointers?
FYI: I discovered this with Burt's Linux port.
Sep 11 2002
"Russell Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message news:3D7F9ECF.4090406 deming-os.org...I tried this: struct asdf { uint thing1; uint thing2; uint thing3; uint thing4; }; asdf foo; asdf* bar; assert(foo.size == 16); // works assert((*bar).size == 16); // works assert(bar.size == 4); // fails!!! It says it fails with "16 == 4", which tells me that when I do bar.size, I'm getting the size of the structure underlying the pointer, NOT the pointer itself. However, if I declare a pointer-to-pointer, I get a size of 4: asdf** fred; assert(fred.size == 4); // works So first of all, does the property of a pointer refer to the pointer, or to the thing it points to? If the former, then how do we get info about the pointer? If the latter, then shouldn't it recurse down through all pointers?
What's happening here is that when faced with a pointer followed by a dot, the semantic analysis inserts one pointer derefence 'for free', so to speak. Clearly, in this case it should not. I'll see about fixing it.
Sep 12 2002
Walter wrote:What's happening here is that when faced with a pointer followed by a dot, the semantic analysis inserts one pointer derefence 'for free', so to speak.
Why doesn't the compiler dereference it several times if necessary? It would be logical...
Sep 12 2002
"Pavel Minayev" <evilone omen.ru> wrote in message news:alqha5$1ii8$1 digitaldaemon.com...Walter wrote:What's happening here is that when faced with a pointer followed by a
the semantic analysis inserts one pointer derefence 'for free', so to
Why doesn't the compiler dereference it several times if necessary? It would be logical...
I'm a little unsure about that. Let's just see how far we get with one level for the moment.
Sep 12 2002
How else will you dereference more than one level? prefix operator * and parens? Sean "Walter" <walter digitalmars.com> wrote in message news:alqmae$2702$3 digitaldaemon.com..."Pavel Minayev" <evilone omen.ru> wrote in message news:alqha5$1ii8$1 digitaldaemon.com...Walter wrote:What's happening here is that when faced with a pointer followed by a
the semantic analysis inserts one pointer derefence 'for free', so to
Why doesn't the compiler dereference it several times if necessary? It would be logical...
I'm a little unsure about that. Let's just see how far we get with one
for the moment.
Sep 13 2002
Yes. "Sean L. Palmer" <seanpalmer earthlink.net> wrote in message news:als2js$p9o$1 digitaldaemon.com...How else will you dereference more than one level? prefix operator * and parens? Sean "Walter" <walter digitalmars.com> wrote in message news:alqmae$2702$3 digitaldaemon.com..."Pavel Minayev" <evilone omen.ru> wrote in message news:alqha5$1ii8$1 digitaldaemon.com...Walter wrote:What's happening here is that when faced with a pointer followed by
dot,the semantic analysis inserts one pointer derefence 'for free', so
speak.Why doesn't the compiler dereference it several times if necessary? It would be logical...
I'm a little unsure about that. Let's just see how far we get with one
for the moment.
Sep 13 2002









Russell Lewis <spamhole-2001-07-16 deming-os.org> 