Why the standard make that difference?
It seems as both designate, in the same way, an atomic type.
Specifier and qualifier are defined in the C++ standard. Qualifier is just an integral part of a specifier. For example, type specifier in a declaration can include cv-qualifiers.
The keywords which are used to modify the property of a variable are called type qualifiers. eg. const volatile. Storage class specifiers in C language tells the compiler where to store a variable, how to store the variable, what is the initial value of the variable and life time of the variable.
In C, _Atomic is used as a type specifier. It is used to avoid the race condition if more than one thread attempts to update a variable simultaneously. It is defined in the stdatomic.
Atomic type specifiers :-:)
Syntax: _Atomic ( type-name );
You can declare an atomic integer like this:
_Atomic(int) counter;
The _Atomic
keyword can 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>
.
Atomic type specifiers shall not be used if the implementation does not support atomic types. The type name in an atomic type specifier shall not refer to an array type, a function type, an atomic type, or a qualified type.
The properties associated with atomic types are meaningful only for expressions that are lvalues.
If the _Atomic keyword is immediately followed by a left parenthesis, it is interpreted as a type specifier (with a type name), not as a type qualifier.
Atomic type qualifiers :-:)
_Atomic volatile int *p;
It specifies that p has the type ‘‘pointer to volatile atomic int’’, a pointer to a volatile-qualified atomic type.
Types other than pointer types whose referenced type is an object type shall not be restrict-qualified.
The type modified by the _Atomic
qualifier shall not be an array type or a function type.
The properties associated with qualified types are meaningful only for expressions that are lvalues.
If the same qualifier appears more than once in the same specifier-qualifier-list, either directly or via one or more typedefs, the behavior is the same as if it appeared only once. If other qualifiers appear along with the _Atomic
qualifier in a specifier-qualifier-list, the resulting type is the so-qualified atomic type.
The keyword _Atomic
is used, alone, as a type qualifier. An implementation is allowed to relax the requirement of having the same representation and alignment of the corresponding non-atomic type, as long as appropriate conversions are made, including via the cast operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With