¿Qué compilador C99 (Clang vs. GCC) está más cerca del estándar en los campos de estructura const?
Tengo un código como este:
$ cat test.c
#include <stdio.h>
typedef struct
{
const int x;
} SX;
static SX mksx(void)
{
return (SX) { .x = 10 };
}
void fn(void)
{
SX sx;
while((sx = mksx()).x != 20)
{
printf("stupid code!");
}
}
Y 2 opiniones sobre su corrección:
$ for i in gcc clang; do echo "$i SAYS:"; $i -c -std=c99 -pedantic -Werror test.c; done
gcc SAYS:
test.c: In function ‘fn’:
test.c:15:2: error: assignment of read-only variable ‘sx’
while((sx = mksx()).x != 20)
^
clang SAYS:
¿Qué compilador tiene razón?