c - 包含 stddef.h 但未声明 max_align_t

标签 c gcc c11

我想编译这段代码:

#include <stdalign.h>
#include <stdio.h>
#include <stddef.h>
int main ( int argc , char ** argv )
{
    printf ("%zu\n", alignof ( max_align_t ));
    return 0;
}

但是编译器说:

error: ‘max_align_t’ undeclared".

stddef.h 包含在内,一切都必须正常,不是吗?

附言我已经尝试在 gcc4.8 和 gcc4.9 下编译这段代码,但出现了所描述的错误。

最佳答案

要使用 C11 功能,您需要告诉编译器以 C11 兼容模式运行。

对于 gcc,这可以通过指定选项 -std=c11 来实现。

关于c - 包含 stddef.h 但未声明 max_align_t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33134621/

相关文章:

objective-c - 类转储 z 生成空 header

c - 函数内部的第二个 scanf 不起作用......程序不会在第二个 scanf 处停止?

python - 使用 Cython 将 Python 编译为 C

c++ - 如何使用 std 库在 Linux 上从 utf-16 转换为 utf-32?

c - (struct *) vs (void *) -- C11/C99 中的函数原型(prototype)等价

c - _Alignas 结构成员使用 clang & C11

是否可以在其定义中取自动存储期限的变量的地址?

c - 在 C 中将浮点值缩放为 (0-100) 的函数

c - KnR 练习 2-8 : Rotate a number to the right. 可以吗?

gcc - 对 `__imp___gmpz_init' 的 undefined reference ,在 Cygwin 上构建 GMP 程序