9.16 Constant expressions

Extended constant expressions are supported in initializers.

The following examples show the compiler behavior for the default, --strict_warnings, and --strict compiler modes.

Example 1, assigning the address of variable

Your code might contain constant expressions that assign the address of a variable at file scope, for example:

int i;
int j = (int)&i; /* but not allowed by ISO */

When compiling for C, this produces the following behavior:

Example 2, constant value initializers

The following table compares the behavior of the ARM compilation tools with the ISO C Standard.

If compiling with --strict_warnings in place of --strict, the example source code that is not valid with --strict become valid. The --strict error message is downgraded to a warning message.

Table 9-1 Behavior of constant value initializers in comparison with ISO Standard C

Example source code ISO C Standard ARM compilation tools
--strict mode Nonstrict mode
extern int const c = 10; Valid Valid Valid
extern int const x = c + 10; Not valid Not valid Valid
static int y = c + 10; Not valid Not valid Valid
static int const z = c + 10; Not valid Not valid Valid
extern int *const cp = (int*)0x100; Valid Valid Valid
extern int *const xp = cp + 0x100; Not valid Not valid Valid
static int *yp = cp + 0x100; Not valid Not valid Valid
static int *const zp = cp + 0x100; Not valid Not valid Valid
Related reference
8.79 --extended_initializers, --no_extended_initializers
8.173 --strict, --no_strict
8.174 --strict_warnings
Non-Confidential PDF file icon PDF version ARM DUI0472J
Copyright © 2010-2013 ARM. All rights reserved.