alibaba / PhotonLibOS

Probably the fastest coroutine lib in the world!

Home Page:https://PhotonLibOS.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

编译

zhanb opened this issue · comments

commented

系统centos8.5, 错误信息如下:
image

gcc 8? What is the minor version exactly?

Could you also try other versions, for instance, gcc-toolset-7 or gcc-toolset-9 ?

Why gcc take static_assert as a macro with 2 parameters? It should be a keyword.

commented

gcc 8? What is the minor version exactly?

Could you also try other versions, for instance, gcc-toolset-7 or gcc-toolset-9 ?

image

commented

Why gcc take static_assert as a macro with 2 parameters? It should be a keyword.

为了回答这个问题,我们需要了解GCC是如何处理static_assert的。GCC是一个编译器,它在编译代码时会对语言标准进行解析和实现。C语言标准从C11开始引入了static_assert关键字,用于在编译时进行静态断言(即在编译时检查一些条件是否为真)。

然而,早期版本的GCC并不支持C11的所有特性,包括static_assert关键字。为了向后兼容旧版本的代码,GCC采取了一种宏的方式来模拟实现static_assert的功能。

这意味着,当使用旧版本的GCC编译器时,它将static_assert解释为一个宏,而不是一个关键字。该宏通常定义在<assert.h>头文件中,接受两个参数:条件表达式和可选的错误消息。

因此,对于旧版本的GCC编译器,您可以通过包含<assert.h>头文件并使用static_assert宏来实现静态断言的功能。然而,对于支持C11及以上版本的GCC编译器,它会将static_assert作为一个关键字进行处理。

需要注意的是,现代的GCC版本已经支持C11标准,并将static_assert作为关键字进行处理。因此,在使用较新版本的GCC时,您可以直接使用static_assert关键字而不是宏。

@zhanb So, you are actually using an old gcc? Or you forget to enable C++11?