编译相同代码时,gcc(赋值给只读)和clang(无错误)之间的不同错误报告背后的原因是什么?
考虑以下C片段:
#include <stdio.h>
struct ex {
const int x;
int y;
};
int main(void)
{
struct ex a;
const struct ex b = {.x = 44, .y = 66};
a = b;
printf("%d, %d\n", a.x, a.y);
printf("%d, %d\n", b.x, b.y);
return 0;
}
gcc (x86_64-posix-seh-rev1, Built by MinGW-W64 project) 6.2.0
test.c: In function 'main':
test.c:11:7: error: assignment of read-only variable 'a'
a = b;
^
clang version 3.9.1 (branches/release_39)
Target: x86_64-pc-windows-msvc
Thread model: posix
<no errors>