dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Mar 23, 2000

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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.

Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date