digitalmars.D.learn - offsetof + foreach
- Ellery Newcomer (8/8) Sep 07 2012 I have a struct buffer, and I want to print out its members' offsetof.
- Ellery Newcomer (3/11) Sep 07 2012 nevermind, I remember tupleof + foreach has always been broken
- Kenji Hara (13/31) Sep 08 2012 I think this is expected behavior.
I have a struct buffer, and I want to print out its members' offsetof. This: foreach(i,_t; buffer.tupleof) { writefln("%s : %s", _t.stringof, _t.offsetof); } complains Error: undefined identifier 'offsetof' what should I be doing?
Sep 07 2012
On 09/07/2012 10:31 AM, Ellery Newcomer wrote:I have a struct buffer, and I want to print out its members' offsetof. This: foreach(i,_t; buffer.tupleof) { writefln("%s : %s", _t.stringof, _t.offsetof); } complains Error: undefined identifier 'offsetof' what should I be doing?nevermind, I remember tupleof + foreach has always been broken writefln("%s : %s", buffer.tupleof[i].stringof, buffer.tupleof[i].offsetof);
Sep 07 2012
On Friday, 7 September 2012 at 17:32:43 UTC, Ellery Newcomer wrote:On 09/07/2012 10:31 AM, Ellery Newcomer wrote:I think this is expected behavior. In foreach body, _t is a copy of field value, and it's not buffer's field itself. Your code is equivalent with: foreach(i,_; buffer.tupleof) { auto _t = buffer.tupleof[i]; // _t is a normal variable writefln("%s : %s", _t.stringof, _t.offsetof); } Then you cannot get offsetof property from _t; Regards. Kenji HaraI have a struct buffer, and I want to print out its members' offsetof. This: foreach(i,_t; buffer.tupleof) { writefln("%s : %s", _t.stringof, _t.offsetof); } complains Error: undefined identifier 'offsetof' what should I be doing?nevermind, I remember tupleof + foreach has always been broken writefln("%s : %s", buffer.tupleof[i].stringof, buffer.tupleof[i].offsetof);
Sep 08 2012