3

Wiki page claimed the qualifiers in C++ are const and volatile.

This answer tells unsigned, unsigned and short, etc. are also qualifiers. Though the the question did mention it is about the C, the Wiki page does not tell so either on the C side. For C the qualifiers are const, volatile, restrict and _Atomic.

And the expanding message box of the qualifier Tag of Stack Overflow says

A qualifier adds an extra "quality", such as specifying volatility or constness of a variable

"Add an extra quality", from the quotation, singed/unsigned seems meet the condition, it added the restricted extra quality to an integer so that it can hold positive number only or the negative one as well.

I'm confused a bit on this issue at the moment. For C and C++, is signed, unsigned and short, etc. counted as part of the base type or the type qualifier? And please elaborate if the rules are different in C and C++.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
SLN
  • 4,772
  • 2
  • 38
  • 79
  • 1
    _"For every type other than reference and function, the type system supports three additional cv-qualified versions of that type (const, volatile, and const volatile)."_ See: http://en.cppreference.com/w/cpp/language/type and http://en.cppreference.com/w/cpp/language/types Also this is probably different for C and C++. – Richard Critten Jan 20 '18 at 15:29
  • 1
    `signed` and `unsigned` cannot be used with any type. C11 `_Generic` is a switch-case by type. It discards `const` and `volatile` qualitfier, but not signess. But does it really matter? You can check the standard, but even then it is still just a word game. –  Jan 20 '18 at 15:30
  • @RichardCritten seems you given 2 same resource url, I guess you mean http://en.cppreference.com/w/c/language/type – SLN Jan 20 '18 at 15:33
  • 1
    @SLN corrected thanks should now say .../type and .../types – Richard Critten Jan 20 '18 at 15:37
  • A qualifier doesn't change what the possible values of a type are. The elements of `int` and `unsigned int` only partially overlap. – molbdnilo Jan 20 '18 at 15:42
  • `singed` is for very hot variables. – Eljay Jan 20 '18 at 15:43
  • @Eljay what is hot variables? – SLN Jan 20 '18 at 15:44
  • 3
    It's somewhat important to distinguish between "qualifier" as defined by the C++ standard, and "qualifier" as defined in a dictionary. Some texts appear to use "qualifier" as a synonym to "specifier", which is not the Standard meaning. – molbdnilo Jan 20 '18 at 15:55
  • @SLN • [singed](https://www.google.com/search?num=1&q=Dictionary#dobs=singed) – Eljay Jan 20 '18 at 16:00
  • 1
    Pictorial representation of the universe of types in C++, and how they are classified: http://howardhinnant.github.io/TypeHiearchy.pdf – Howard Hinnant Jan 20 '18 at 17:21
  • @HowardHinnant thx, that's a good illustration! – SLN Jan 20 '18 at 17:27

2 Answers2

3

In both C and C++, signed, unsigned, short and long are type specifier. They can be combined with int, even implicitly. signed and unsigned can also be combined with char.

In contrast, qualifiers can be applied to almost any type. (There's no int& const type, only int const&)

MSalters
  • 173,980
  • 10
  • 155
  • 350
2

According to the C11 standard (§6.7.3), the type qualifiers are const, restrict, volatile and _Atomic. signed and unsigned fall under type specifiers (§6.7.2).

Kninnug
  • 7,992
  • 1
  • 30
  • 42