c - Dereferencing pointer type when in sizeof() -
i have following structure:
typedef struct _foo_t { int bar; float buzz; char quux[40]; } *const foo_t; is there way size of structure, it's done via sizeof(struct _foo_t), using name foo_t? have tried sizeof(*foo_t), not compile.
i don't believe can directly. you'll need define intermediate typedef if want this:
typedef struct _foo_t { int bar; float buzz; char quux[40]; } foo_t; typedef foo_t *const foo_tp; // sizeof(foo_t) should work dereferencing type doesn't make sense in c. can dereference variable, not type. in c++, can these kinds of type operations using templates, that's not applicable since indicate c tag.
you declare dummy variable of appropriate type invoke sizeof on expression:
foo_tp f; // sizeof(*f) should work
Comments
Post a Comment