The size of a struct
is determined much earlier in the compilation than the setting of the values inside the struct
.
What's the behavior of sizeof used in member initializer?
سؤال
What's the behavior of sizeof used in member initializer? I can't find a description about exactly that. In the below code example is it safe? ie, after struct
member will the compiler put right size of A
in b
?
struct A
{
int a = 0;
int b = sizeof(A);
int c = 3;
int d = 4;
char s[256];
A()
{
//printf("b = %d\n", b);
}
};
المحلول
لا تنتمي إلى StackOverflow