D - Bug: Properties of pointers
- Russell Lewis (17/17) Sep 11 2002 I tried this:
- Russell Lewis (2/25) Sep 11 2002 FYI: I discovered this with Burt's Linux port.
- Walter (5/22) Sep 12 2002 What's happening here is that when faced with a pointer followed by a do...
- Pavel Minayev (3/5) Sep 12 2002 Why doesn't the compiler dereference it several times if necessary?
- Walter (6/11) Sep 12 2002 dot,
- Sean L. Palmer (6/17) Sep 13 2002 How else will you dereference more than one level? prefix operator * an...
- Walter (5/24) Sep 13 2002 Yes.
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:dot,What's happening here is that when faced with a pointer followed by aspeak.the semantic analysis inserts one pointer derefence 'for free', so toWhy 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...levelWalter wrote:dot,What's happening here is that when faced with a pointer followed by aspeak.the semantic analysis inserts one pointer derefence 'for free', so toWhy 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 onefor 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...a"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 bytodot,the semantic analysis inserts one pointer derefence 'for free', sospeak.levelWhy 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 onefor the moment.
Sep 13 2002