gcc和clang之间的常数差异

时间:2017-02-14 11:11:04

标签: c gcc struct clang const

编译相同代码时,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

- 版本

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;
       ^

- 版本

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>

0 个答案:

没有答案