What are the various error reports between gcc (read-only assignment) and clang (no errors) when compiling the same code?
Consider the following C code snippet:
#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;
}
NCA
- version
gcc (x86_64-posix-seh-rev1, Built by MinGW-W64 project) 6.2.0
gcc -Wall -Wextra -pedantic -std = c99 test.c
test.c: In function 'main':
test.c:11:7: error: assignment of read-only variable 'a'
a = b;
^
clank
- version
clang version 3.9.1 (branches/release_39)
Target: x86_64-pc-windows-msvc
Thread model: posix
clang -Weverything -std = c99 test.c
<no errors>
baeda source
share