8.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:
  • In default mode a warning is produced.
  • In --strict_warnings mode a warning is produced.
  • In --strict mode, an error is produced.

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 8-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
7.62 --extended_initializers, --no_extended_initializers
7.156 --strict, --no_strict
7.157 --strict_warnings
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.