Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correlation between specifier and qualifier?

Tags:

c++

lvalue

const and volatile are called cv-qualifier by the C spec.

What is exactly defference between specifier and qualifier (cv-qualifier)? Is a qualifier is a specifier as well?

Is it necessarry that qualifier is with an lvalue only?

What are qualifiers other than cv-qualifier?

Does my above understanding make any sense?

like image 609
Sudhendu Sharma Avatar asked Aug 31 '10 16:08

Sudhendu Sharma


People also ask

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 a qualifier in programming?

In the C, C++, and D programming languages, a type qualifier is a keyword that is applied to a type, resulting in a qualified type. For example, const int is a qualified type representing a constant integer, while int is the corresponding unqualified type, simply an integer.

What is cv qualified?

CV stands for Constant-Volatile. The declaration of an object that is not preceded by const and/or volatile is a cv-unqualified type. On the other hand, the declaration of an object that is preceded by const and/or volatile is a cv-qualified type.


1 Answers

Most of it doesn't make sense.

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. I don't see the reason to quote everything from the standard on this topic.

Cv-qualifiers are not restricted to lvalues. Rvalues of class types can also be cv-qualified. It is possible to cv-qualify an rvalue of non-class type, but it will have no effect and will be ignored.

The use of const qualifier that you show in your example with foo is just a syntactic form, which actually means that the const-qualifier is applied to the implied this parameter of the foo method: const A* this. I.e. in this case it does indeed qualify an lvalue, but it is *this, not foo.

The term qualifier also appears in the context of qualified names. Name like some_class::some_member (or some_namespace::some_name) are called qualified names and the some_class:: part is a qualifier.

The idea that if something is an lvalue then you can modify it is totally incorrect. There are modifiable lvalues and non-modifiable lvalues. An object declared as const int i = 5 is an lvalue, yet you can't modify it. Ordinary functions are also lvalues in C++, yet you can't modify a function.

like image 83
AnT Avatar answered Oct 14 '22 14:10

AnT