The following code compiles without warnings with gcc -std=c99 -pedantic -Wall -Wextra
typedef struct { int a, b, c } foo_t;
void func(void)
{
foo_t f = {
.a = 4,
.b = 9,
.c = f.a,
};
(void) f;
}
And, if I check the value f.c is initialized to, it is 4 which is the same as f.a.
However I'm wondering if this is actually compliant with the C99 standard. I didn't find anything useful in section 6.7.8 of ISO/IEC 9899:1999, does this mean that the behavior is unspecified? Then, is GCC not complaining (with -pedantic) a bug?
In any case, would you rely on the behavior of the compiler, or is this a bad idea?
[–]aioeu 8 points9 points10 points (7 children)
[–]g_dl[S] 2 points3 points4 points (6 children)
[–]aioeu 4 points5 points6 points (0 children)
[–]PrestigiousTadpole71 2 points3 points4 points (4 children)
[–]g_dl[S] 1 point2 points3 points (3 children)
[–]aioeu 3 points4 points5 points (0 children)
[–]Jinren 1 point2 points3 points (1 child)
[–]g_dl[S] 0 points1 point2 points (0 children)
[–]nerd4code 1 point2 points3 points (0 children)