Object - part of the language, or part of Phobos?
Jacob Carlborg
doob at me.com
Sat Oct 1 04:47:00 PDT 2011
On 2011-10-01 08:20, Steve Teale wrote:
> Jonathan,
>
> I had a secondary question - under what circumstances is the OffsetTypeInfo available?
>
> Since it's not part of the language, I guess whoever implemented the current
> runtime just chose not to provide it, or it's a bug. I'll check out the code.
>
> I want to associate a struct with a database row in my database wrapper, and that
> information would be very useful. The struct.tupleof goes so far, but the offset
> information is not accessible unless you know what field to ask for it on.
>
> Steve
I'm pretty sure the compiler needs to provide this information, then the
runtime puts it in OffsetTypeInfo. If it doesn't there's no way to
provided that using OffsetTypeInfo.
Are you really sure you want to depend on the field offset of a struct?
If the order of the fields in the struct change, won't all code the that
relies on the offset break?
Wouldn't it be much better to depend on the names instead?
If you really want to use the offset you should be able to use:
Struct.field.offsetof;
Documented here: http://www.d-programming-language.org/struct.html
Search for "Struct Field Properties".
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list