Keil Logo

Language extension compatibility: pragmas

4.3 Language extension compatibility: pragmas

Arm® Compiler 6 provides support for some pragmas that are supported in Arm Compiler 5. Other pragmas are not supported, or must be replaced with alternatives.

The following table lists some of the commonly used pragmas that are supported by Arm Compiler 5 but are not supported by Arm Compiler 6. Replace any instances of these pragmas in your code with the recommended alternative.

Table 4-5 Pragma language extensions that must be replaced

Pragma supported by Arm Compiler 5 Recommended Arm Compiler 6 alternative
#pragma import (symbol)
__asm(".global symbol\n\t");

#pragma anon_unions

#pragma no_anon_unions

In C, anonymous structs and unions are a C11 extension which is enabled by default in armclang. If you specify the -pedantic option, the compiler emits warnings about extensions do not match the specified language standard. For example:

armclang --target=aarch64-arm-none-eabi -c -pedantic --std=c90 test.c
  test.c:3:5: warning: anonymous structs are a C11 extension [-Wc11-extensions]

In C++, anonymous unions are part of the language standard, and are always enabled. However, anonymous structs and classes are an extension. If you specify the -pedantic option, the compiler emits warnings about anonymous structs and classes. For example:

armclang --target=aarch64-arm-none-eabi -c -pedantic -xc++  test.c 
  test.c:3:5: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]

Introducing anonymous unions, struct and classes using a typedef is a separate extension in armclang, which must be enabled using the -fms-extensions option.

#pragma arm

#pragma thumb

armclang does not support switching instruction set in the middle of a file. You can use the command-line options -marm and -mthumb to specify the instruction set of the whole file.
#pragma arm section

#pragma clang section

In Arm Compiler 5, the section types you can use this pragma with are rodata, rwdata, zidata, and code. In Arm Compiler 6, the equivalent section types are rodata, data, bss, and text respectively.

#pragma diag_default

#pragma diag_suppress

#pragma diag_remark

#pragma diag_warning

#pragma diag_error

The following pragmas provide equivalent functionality for diag_suppress, diag_warning, and diag_error:

  • #pragma clang diagnostic ignored "-Wmultichar"
  • #pragma clang diagnostic warning "-Wmultichar"
  • #pragma clang diagnostic error "-Wmultichar"

Note that these pragmas use armclang diagnostic groups, which do not have a precise mapping to armcc diagnostic tags.

armclang has no equivalent to diag_default or diag_remark. diag_default can be replaced by wrapping the change of diagnostic level with #pragma clang diagnostic push and #pragma clang diagnostic pop, or by manually returning the diagnostic to the default level.

There is an additional diagnostic level supported in armclang, fatal, which causes compilation to fail without processing the rest of the file. You can set this as follows:

#pragma clang diagnostic fatal "-Wmultichar"

#pragma exceptions_unwind

#pragma no_exceptions_unwind

armclang does not support these pragmas.

Use the __attribute__((nothrow)) function attribute instead.

#pragma GCC system_header

This pragma is supported by both armcc and armclang, but #pragma clang system_header is the preferred spelling in armclang for new code.

#pragma hdrstop

#pragma no_pch

armclang does not support these pragmas.

#pragma import(__use_no_semihosting)

#pragma import(__use_no_semihosting_swi)

armclang does not support these pragmas. However, in C code, you can replace these pragmas with:

__asm(".global __use_no_semihosting\n\t");

#pragma inline

#pragma no_inline

armclang does not support these pragmas. However, inlining can be disabled on a per-function basis using the __attribute__((noinline)) function attribute.

The default behavior of both armcc and armclang is to inline functions when the compiler considers this worthwhile, and this is the behavior selected by using #pragma inline in armcc. To force a function to be inlined in armclang, use the __attribute__((always_inline)) function attribute.

#pragma Onum

#pragma Ospace

#pragma Otime

armclang does not support changing optimization options within a file. Instead these must be set on a per-file basis using command-line options.

#pragma pop

#pragma push

armclang does not support these pragmas. Therefore, you cannot push and pop the state of all supported pragmas.

However, you can push and pop the state of the diagnostic pragmas and the state of the pack pragma.

To control the state of the diagnostic pragmas, use #pragma clang diagnostic push and #pragma clang diagnostic pop.

To control the state of the pack pragma, use #pragma pack(push) and #pragma pack(pop).

#pragma softfp_linkage

armclang does not support this pragma. Instead, use the __attribute__((pcs("aapcs"))) function attribute to set the calling convention on a per-function basis, or use the -mfloat-abi=soft command-line option to set the calling convention on a per-file basis.

#pragma no_softfp_linkage

armclang does not support this pragma. Instead, use the __attribute__((pcs("aapcs-vfp"))) function attribute to set the calling convention on a per-function basis, or use the -mfloat-abi=hard command-line option to set the calling convention on a per-file basis.

#pragma unroll[(n)]

#pragma unroll_completely

armclang supports these pragmas.

The default for #pragma unroll (that is, with no iteration count specified) differs between armclang and armcc:

  • With armclang, the default is to fully unroll a loop.
  • With armcc, the default is #pragma unroll(4).
Non-ConfidentialPDF file icon PDF version100068_0613_00_en
Copyright © 2014–2019 Arm Limited or its affiliates. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.