C++ Types

From Schmid.wiki
Jump to: navigation, search

Contents

Types

Type Modifiers

declared at global scope - global
extern                   - declare, but don't define
auto (default)           - local to current scope, destroy when out of scope
register                 - tell compiler to optimze for access to this variable
static                   - local to current scope, don't destroy
static inside class      - common to all class instances
const                    - immutable
volatile                 - may change as result of other process
                           don't make optimizations that expect it not to change

Deprecated:

static at global scope   - unavailable outside of this file

Declarations

Syntax:

[specifier] base_type declarator [initializer]

Example:

const       unsigned int *char[]    = {"stuff"};
specifier   base_type    declarator initializer

Declarator prefix operators:

*
*const - constant pointer
&

Declarator postfix operators - these "bind tighter" than prefix operators:

[]
() - function

Definitions

The following definitions are equivalent:

X x(1);
X y = X(1);
X z = 1;

where X can be any type. Gcc generates the same code for each of them.

Personal tools