Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between the _Atomic type qualifier and type specifier?

Tags:

c

Why the standard make that difference?

It seems as both designate, in the same way, an atomic type.

like image 240
xdevel2000 Avatar asked Oct 20 '14 10:10

xdevel2000


People also ask

What are specifier and qualifier?

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.

What is specifier and qualifier in C?

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.

What is _atomic in C?

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.


1 Answers

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.

like image 65
Anbu.Sankar Avatar answered Oct 21 '22 18:10

Anbu.Sankar