digitalmars.D - Introspection
- Sean Kelly (18/18) Sep 23 2008 Does anyone know a way to determine the type and offset of class/struct ...
- BCS (13/37) Sep 23 2008 import std.stdio;
- BCS (13/38) Sep 23 2008 cleaner:
- Sean Kelly (4/42) Sep 23 2008 Huh, e.offsetof doesn't work but C.tupleof[i].offsetof does. At least I
- Sean Kelly (3/20) Sep 23 2008 Hm, now that I think about it, I bet this is possible with string mixins...
Does anyone know a way to determine the type and offset of class/struct members? It seems we already have all the necessary pieces, but I haven't been able to get it to work thus far. What I'm thinking of is something like this: import std.stdio; class C { int i; void* p; } void main() { foreach( e; typeof(C.tupleof) ) writefln( e.stringof, " ", e.offsetof ); } However, offsetof doesn't appear to work on the members of this TypeTuple, nor on an instance tuple. I've also tried various attempts at printing the address or value of the instance tuple, with no success. Sean
Sep 23 2008
Reply to Sean,Does anyone know a way to determine the type and offset of class/struct members? It seems we already have all the necessary pieces, but I haven't been able to get it to work thus far. What I'm thinking of is something like this: import std.stdio; class C { int i; void* p; } void main() { foreach( e; typeof(C.tupleof) ) writefln( e.stringof, " ", e.offsetof ); } However, offsetof doesn't appear to work on the members of this TypeTuple, nor on an instance tuple. I've also tried various attempts at printing the address or value of the instance tuple, with no success. Seanimport std.stdio; class C { int i; void* p; } void main() { C c = new C; foreach( i,e; c.tupleof ) writefln( typeof(e).stringof, " ", c.tupleof[i].offsetof ); }
Sep 23 2008
Reply to Benjamin,Reply to Sean,cleaner: import std.stdio; class C { int i; void* p; } void main() { foreach( i,e; typeof(C.tupleof) ) writefln( e.stringof, " ", C.tupleof[i].offsetof ); }Does anyone know a way to determine the type and offset of class/struct members? It seems we already have all the necessary pieces, but I haven't been able to get it to work thus far. What I'm thinking of is something like this: import std.stdio; class C { int i; void* p; } void main() { foreach( e; typeof(C.tupleof) ) writefln( e.stringof, " ", e.offsetof ); } However, offsetof doesn't appear to work on the members of this TypeTuple, nor on an instance tuple. I've also tried various attempts at printing the address or value of the instance tuple, with no success. Sean
Sep 23 2008
== Quote from BCS (ao pathlink.com)'s articleReply to Benjamin,Huh, e.offsetof doesn't work but C.tupleof[i].offsetof does. At least I was close :-) Thanks! SeanReply to Sean,cleaner: import std.stdio; class C { int i; void* p; } void main() { foreach( i,e; typeof(C.tupleof) ) writefln( e.stringof, " ", C.tupleof[i].offsetof ); }Does anyone know a way to determine the type and offset of class/struct members? It seems we already have all the necessary pieces, but I haven't been able to get it to work thus far. What I'm thinking of is something like this: import std.stdio; class C { int i; void* p; } void main() { foreach( e; typeof(C.tupleof) ) writefln( e.stringof, " ", e.offsetof ); } However, offsetof doesn't appear to work on the members of this TypeTuple, nor on an instance tuple. I've also tried various attempts at printing the address or value of the instance tuple, with no success. Sean
Sep 23 2008
== Quote from Sean Kelly (sean invisibleduck.org)'s articleDoes anyone know a way to determine the type and offset of class/struct members? It seems we already have all the necessary pieces, but I haven't been able to get it to work thus far. What I'm thinking of is something like this: import std.stdio; class C { int i; void* p; } void main() { foreach( e; typeof(C.tupleof) ) writefln( e.stringof, " ", e.offsetof ); } However, offsetof doesn't appear to work on the members of this TypeTuple, nor on an instance tuple. I've also tried various attempts at printing the address or value of the instance tuple, with no success.Hm, now that I think about it, I bet this is possible with string mixins and __traits. Sean
Sep 23 2008