Keil Logo

ARMCLANG: Compiling a char array faster


Information in this knowledgebase article applies to:

  • ARMCC v4.1.0.481 or newer versions
  • Armclang v6.0 or newer versions

SYMPTOM

A program includes a very large array with elements of type char. This takes a long time to compile when initialized like the following:

const char Web[#...#] = { 0x00U, 0x01U, 0x02U, ... };

Is there a better way to initialize the array, for a faster build time?

CAUSE

Defining an array, like above, requires the parsing of each individual element for error or warning messages later. For char arrays, that do not require debugging diagnostics, there is a better way.

RESOLUTION

A broad alternative for large arrays is to build them once as a library, then add the library into the main project or target. A pre-compiled array incrementally affects a linker's performance.

For char arrays, initialize the array, in the following syntax:

const char Web[#...#] = "\x00\x01\x02...";

Note the lack of commas. Users can only do this with unsigned, one-byte sized elements, because the compiler treats the information like a one-line string. A third party editor may be required to remove carriage returns between lines of the earlier array definition.

This syntax will dramatically reduce the build time for the array. For extremely large arrays or slower PCs, this syntax can decrease build times by several seconds or more.

Last Reviewed: Monday, December 21, 2020


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  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.