c - C11 _Atomic 说明符与限定符语法不规则的基本原理?

标签 c language-lawyer grammar atomic c11

这里有一个相关的“什么”问题:C11 grammar ambiguity between _Atomic type specifier and qualifier

我感兴趣的是为什么,因为 C11 基本原理尚未发布,这似乎不必要地复杂。

语法包括这两者(并解决了有利于 shifting ( 而不是 reduce 的歧义(否则会是如果后跟 declaratorabstract-declarator)),可从 declaration-specifiersspecifier-qualifier-list< 访问:

atomic-type-specifier: _Atomic ( type-name )
type-qualifier: _Atomic

这导致以下代码:

int i1;
int (i2); // valid, same as i1 - usually seen in the context of pointer-to-function or pointer-to-array
int _Atomic a1;
int _Atomic (a2); // invalid
_Atomic (int) a3; // valid, same as a1

想法:

  • _Atomic 不得修改数组或函数。除非声明符周围有多余的括号,这意味着 #define _Atomic(x) x _Atomic 是有效的(当然如果 #define 关键字是合法的)。

  • 当它作为限定符出现时,_Atomicconst 是相同的句法部分,C 程序员 已经习惯于将 const 放在正确的一侧,所以不能为了“易于使用”。

最佳答案

基本原理可在 N1485 中找到:

The _Atomic keyword also can also be used in the form _Atomic(T), where T is a type, as a type specifier equivalent to _Atomic T. Thus, _Atomic(T) x, y; declares x and y with the same type, even if T is a pointer type. This allows for trivial C++0x compatibility with a C++ only _Atomic(T) macro definition as atomic<T>.

关于c - C11 _Atomic 说明符与限定符语法不规则的基本原理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36381380/

相关文章:

c++ - Bison :轮类减少冲突

python - 你如何用 pyparsing 解析文字星号?

android - 映射共享库时出错

c - 为什么 MSVC 预处理器连接 token 的方式与 GCC 和 Clang 不同?

c - 嵌入式系统中的AT命令

c++ - `T&` 和 `const T&` 对于 all-const 类的区别

c++ - 什么时候允许推导 initializer_list?

c++ - 函数模板的非最后默认模板参数

c++ - 语法到 Lex/Yacc

C 使用IPC消息队列的信号使用及处理