I'm trying to get size of inner structure i.e. struct B
. But I'm getting compilation error:
prog.c: In function ‘main’: prog.c:10:53: error: expected ‘)’ before ‘:’ token printf("%d | %d", sizeof(struct A), sizeof(struct A::struct B));
Following is my code:
#include <stdio.h>
struct A
{
struct B{};
};
int main() {
printf("%d | %d", sizeof(struct A), sizeof(struct A::struct B));
return 0;
}
Could you suggest that how I can achieve this in C?
UPDATED
Answer from @Jabberwocky solves my above problem. But What about following code. This can also be found here:
#include <stdio.h>
struct A
{
struct B{};
};
struct B
{};
int main() {
printf("%d | %d", sizeof(struct A), sizeof(struct B), sizeof(struct A::struct B));
return 0;
}
In this case I'm getting compilation error as following:
prog.c:8:8: error: redefinition of ‘struct B’
struct B
^
prog.c:5:10: note: originally defined here
struct B{};
^
prog.c: In function ‘main’:
prog.c:12:71: error: expected ‘)’ before ‘:’ token
printf("%d | %d", sizeof(struct A), sizeof(struct B), sizeof(struct A::struct B));
Here how I can diffrentiate between struct B
and struct A::struct B