GNU Compiler Collection

The GNU C++ compiler has many extensions to the standard. The most widespread version, 2.95, is mature, stable, but very much outdated with regard to the C++ standard. The new 3.x version hews much closer to the standard, while retaining the familiar GNU extensions. This section presents highlights of only a few of the extensions.

_ _attribute_ _

A function can be modified with attributes to tell the compiler about the function. For example, _ _attribute_ _((noreturn)) tells the compiler that the function does not return, which enables the compiler to remove unneeded code, such as statements that follow calls to the function. Some attributes can apply to objects, labels, and types. Several different attributes are supported, such as:

always_inline

Always expand this function inline, even if optimizations are disabled.

const

The function has no side effects and does not depend on any global variables; therefore, the compiler can replace repeated calls to the function with a single call, saving the result.

deprecated

The function, object, or type is deprecated. Using a deprecated entity results in a compiler warning.

dllexport

On Windows, marks the function as exported from a DLL.

pure

Slightly less strong than const, a pure function has no side effects but can depend on global variables. The compiler can optimize away repeated calls when it knows intervening code does not modify any global variables.

case range

In a switch statement, a single case label can specify a ...

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.