G
grid
Hi,
I have the following code that seems to fail :
#include<stdio.h>
char c = "hello"[0];
int main()
{
printf("c == [%c]\n",c);
return 0;
}
And the below snippet passes :
#include<stdio.h>
int main()
{
char c = "hello"[0];
printf("c == [%c]\n",c);
return 0;
}
From the standard :
All objects in static storage shall be initialized (set to their initial
values) before program startup. The manner and timing of such
initialization are otherwise unspecified.
But I can see in one compiler that it dosent even warn and compiles
cleanly though gcc cribs about it that "initializer element is not
constant".
Which behaviour seems to be correct ??
TIA
~
I have the following code that seems to fail :
#include<stdio.h>
char c = "hello"[0];
int main()
{
printf("c == [%c]\n",c);
return 0;
}
And the below snippet passes :
#include<stdio.h>
int main()
{
char c = "hello"[0];
printf("c == [%c]\n",c);
return 0;
}
From the standard :
All objects in static storage shall be initialized (set to their initial
values) before program startup. The manner and timing of such
initialization are otherwise unspecified.
But I can see in one compiler that it dosent even warn and compiles
cleanly though gcc cribs about it that "initializer element is not
constant".
Which behaviour seems to be correct ??
TIA
~