Skip to Main Content
The D Programming Language
book

The D Programming Language

by Andrei Alexandrescu
June 2010
Intermediate to advanced content levelIntermediate to advanced
456 pages
14h 48m
English
Addison-Wesley Professional
Content preview from The D Programming Language

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced UNIX Programming, Second Edition

Advanced UNIX Programming, Second Edition

Marc J. Rochkind
Learn LLVM 12

Learn LLVM 12

Kai Nacke

Publisher Resources

ISBN: 9780321659538Purchase book