Idempotent Type Qualifiers

Idempotent Type Qualifiers

The type qualifiers const and volatile are idempotent. This means that if a type qualifier is included indirectly several times in a type specification (e.g., through a typedef or a template parameter), it’s treated as if it appeared only once. For example:

   typedef const int CI;

The typedef CI is a synonym for “const int”. Now suppose we declare another typedef based on CI:

   typedef const CI CCI;  

CCI is a synonym for “const CI”, which is actually “const const int”. The compiler ignores the redundant const and treats CCI as a synonym for “const int”. For example:

   int f(CCI n); // fine, f takes a const int

Remember that this rule applies to indirect inclusion of a type qualifier; direct repetitions are illegal:

   void f(const const int); // ill-formed 

In C99, this restriction was relaxed and even direct repetitions are allowed.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular