0

I need something that will work with the following:

struct thing *s;
printf("the size of %s is %d", s->type, (int) sizeof(s->type));

I thought I had at last found a solution with typedef, but no:

struct thing {
  typedef int type;
}

expects syntax of the form thing::type. I suspect the solution still involves typedef, but I need the type to actually be a member, as opposed to a nested type.

Edit: Whoops, looks like the functionality I needed was just a string after all. Sorry, thanks for helping!

Elliot Way
  • 243
  • 1
  • 9

1 Answers1

1

I think this is likely the closest you can do at the moment, although the type name will likely be mangled (not found an implementation that isn't yet):

struct thing {
  int i;
};

thing t;
std::cout << "the size of " << typeid(t.i).name() 
          << " is " << sizeof(t.i) << "\n";
goji
  • 6,911
  • 3
  • 42
  • 59