3.4.1. 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 compiler behavior when you have expressions that include constant values in C code is summarized in the following example:

                                      /*  Std    RVCT v3.1  */
extern int  const c = 10;             /*  ok        ok      */
extern int  const x = c + 10;         /* error      ext     */
static int        y = c + 10;         /* error      ext     */
static int  const z = c + 10;         /* error      ext     */
extern int *const cp = (int*)0x100;   /*  ok        ok      */
extern int *const xp = cp + 0x100;    /* error      ext     */
static int *      yp = cp + 0x100;    /* error      ext     */
static int *const zp = cp + 0x100;    /* error      ext     */

This indicates the behavior defined by the ISO C Standard, Std, and the behavior in RVCT:

  • ok indicates that the statement is accepted in all C modes.

  • ext is an extension to the ISO C Standard. The behavior depends on the strict mode used when compiling C:

    Non strict

    Accepted, without a warning.


    Accepted, but gives a warning.


    Conforms to the ISO C Standard, but gives an error.

See also

Copyright © 2007, 2010 ARM Limited. All rights reserved.ARM DUI 0348A