digitalmars.D.learn - I think is a bug?
- Random D user (20/20) Mar 11 2017 int*[] foo;
- ketmar (2/3) Mar 11 2017 due to automatic pointer dereferencing that `.` does. no, not a bug.
- Random D user (24/28) Mar 11 2017 Ah... right. Silly me. Of course, since string is actually
int*[] foo; foo.length = 5; import std.c.string; int* baz = cast(string*)malloc(50); import std.c.stdio; printf("%d %d", foo.length, baz.length ); prints: Error: no property 'length' for type 'int*' BUT: string*[] foo; foo.length = 5; import std.c.string; string* baz = cast(string*)malloc(50); import std.c.stdio; printf("%d %d", foo.length, baz.length ); compiles and prints: 5 -842150451 How come string* suddenly has a .length property? Anyway the result is garbage, so I think this must be a bug. DMD32 D Compiler v2.073.2
Mar 11 2017
Random D user wrote:How come string* suddenly has a .length property?due to automatic pointer dereferencing that `.` does. no, not a bug.
Mar 11 2017
On Sunday, 12 March 2017 at 01:55:20 UTC, ketmar wrote:Random D user wrote:Ah... right. Silly me. Of course, since string is actually immutable(char)[]. That's bit of a nasty corner case where -> == . isn't that nice. Fortunately, it's rare. Thanks. This happened to me, when I was packing stuff into SoA layout and didn't want to duplicate the length in the struct (implicitly by using []). Of course, I forgot to update one place to use the shared length. That is: length ptr ptr ptr instead of ptr length ptr length ptr length Perhaps I should do a SoA layout template that somehow disables .length on individual arrays.How come string* suddenly has a .length property?due to automatic pointer dereferencing that `.` does. no, not a bug.
Mar 11 2017