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?
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 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.
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.
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.
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