When compiling this code sample
#include <stdio.h>
#include <stdlib.h>
int myfunc()
{
printf("Constructor\n");
return 1;
}
static const int dummy = myfunc();
int main()
{
printf("main\n");
return 0;
}
it works when compiled as C++, but not as C using the same compiler (MingW gcc). I get an initializer element is not constant
in C mode.
So apparently there are differences regarding static intialization. Is there a reason why this is apparently allowed for C++ but not for C? Is this because otherwise you wouldn't be able to have global objects with constructor functions?