Listing 4
#include <iostream> int main() { struct S { int marker1; int marker2; int item1; int item2; }; #define DISPATCH_ID(S, item) ((offsetof(S, item) - offsetof(S, marker2)) / (offsetof(S, marker2) - offsetof(S, marker1))) std::cout << DISPATCH_ID(S, item1) << "," << DISPATCH_ID(S, item2); return 0; }