On Monday, 5 May 2014 at 03:57:54 UTC, Andrey wrote:
Guys, could someone help me with suitable template?

I have C macro, which calculates the offset of the field in a struct:

#define offsetof(type, field)   ((long) &((type *)0)->field)

A similar D code is, as far as I know,

type.field.offsetof

Is there an any way to make a corresponding D template?

Thank you!

Something like:

unittest {
enum offsetof(string type, string field) = mixin(type ~ "." ~ field ~ ".offsetof");

  struct StrToBob {
    string str;
    int bob;
  }

  writeln(offsetof!("StrToBob", "bob"));
}

?

If not that then I'm not sure what you're asking for.

Reply via email to