O'Reilly logo

The D Programming Language by Andrei Alexandrescu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Type Qualifiers

Type qualifiers capture important assertions about types in a language. Such assertions are highly useful to programmers and compilers alike but are difficult to capture by using conventions, regular subtyping (§ 6.4.2 on page 192), or type parameterization (§ 6.14 on page 233).

The canonical example of a type qualifier is const (introduced by C and refined by C++), which, when attached to a type T, expresses the assertion that T values can be initialized and read but never written to. The compiler ensures that the assertion is observed. The const qualifier is quite useful at module boundaries because it gives callers guarantees about functions. For example, the signature

Click here to view code image

// C standard function ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required