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_inlineAlways expand this function inline, even if optimizations are disabled.
constThe 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.
deprecatedThe function, object, or type is deprecated. Using a
deprecatedentity results in a compiler warning.dllexportOn Windows, marks the function as exported from a DLL.
pureSlightly 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.
caserangeIn a
switchstatement, a singlecaselabel can specify a ...