You copied the Doc URL to your clipboard.

Arm Compiler User Guide : Selecting source language options

Selecting source language options

Arm® Compiler infers the source language, for example C or C++, from the filename extension. You can force Arm Compiler to compile for a specific source language using the -x option. Arm Compiler can also compile different variants of C and C++ source code. You can specify the variant using the -std option.

Note

This topic includes descriptions of [COMMUNITY] features. See Support level definitions.

Source language

By default Arm Compiler treats files with .c extension as C source files. If you want to compile a .c file, for example file.c, as a C++ source file, use the -xc++ option:

armclang --target=aarch64-arm-none-eabi -march=armv8-a -xc++ file.c

By default Arm Compiler treats files with .cpp extension as C++ source files. If you want to compile a .cpp file, for example file.cpp, as a C source file, use the -xc option:

armclang --target=aarch64-arm-none-eabi -march=armv8-a -xc file.cpp

The -x option only applies to input files that follow it on the command line.

Source language standard

Arm Compiler supports Standard and GNU variants of source languages as shown in the following table.

Table 2-1 Source language variants

Standard C GNU C Standard C++ GNU C++
c90 gnu90 c++98 gnu++98
c99 gnu99 c++03 gnu++03

c11 [COMMUNITY]

gnu11 [COMMUNITY]

c++11 gnu++11
- - c++14 gnu++14
- -

c++17 [COMMUNITY]

gnu++17 [COMMUNITY]

The default language standard for C code is gnu11 [COMMUNITY]. The default language standard for C++ code is gnu++14. To specify a different source language standard, use the -std=name option.

Arm Compiler supports various language extensions, including GCC extensions, which you can use in your source code. The GCC extensions are only available when you specify one of the GCC C or C++ language variants. For more information on language extensions, see the Arm® C Language Extensions in Arm Compiler.

Since Arm Compiler uses the available language extensions by default, it does not adhere to the strict ISO Standard. To compile to strict ISO standard for the source language, use the -Wpedantic option. This shows warnings where the source code violates the ISO Standard. Arm Compiler does not support strict adherence to C++98 or C++03.

If you do not use -Wpedantic, Arm Compiler uses the available language extensions without warning. However, where language variants produce different behavior, the behavior of the language variant specified by -std will apply.

Note

Certain compiler optimizations can violate strict adherence to the ISO Standard for the language. To identify when these violations happen, use the -Wpedantic option.

The following example shows the use of a variable length array, which is a C99 feature. In this example, the function declares an array i, with variable length n.

#include <stdlib.h>

void function(int n) {
    int i[n];
}

Arm Compiler does not warn when compiling the example for C99 with -Wpedantic:

armclang --target=aarch64-arm-none-eabi -march=armv8-a -c -std=c99 -Wpedantic file.c

Arm Compiler does warn about variable length arrays when compiling the example for C90 with -Wpedantic:

armclang --target=aarch64-arm-none-eabi -march=armv8-a -c -std=c90 -Wpedantic file.c

In this case armclang gives the following warning:

file.c:4:8: warning: variable length arrays are a C99 feature [-Wvla-extension]
int i[n];
^
1 warning generated.
Was this page helpful? Yes No