Search code examples
cembeddediar

Strange definition in C with @ sign


I have come across following definition in an embedded C source file:

const preamble_t OAD_Preamble @ ".preamble" =
{
  HAL_OAD_RC_MAX,       // Default program length of max if not using post-processing tool.
  OAD_MANUFACTURER_ID,  // Manufacturer ID
  OAD_TYPE_ID,          // Image Type
  0x00000001            // Image Version
};

I have no idea about the @ part, can you please help me with this?

Edit: This is in IAR compiler, used with TI SoCs.


Solution

  • This is the way you can specify a memory address or a section in which you would like to place your variable.

    • ".preamble" is the name of a section,
    • OAD_Preamble is the variable to be placed there.

    You can also specify physical address after the at @ sign:

    const unsigned char port_bit @ 0x1800 = BIT0;
    

    More information is in this document.

    Note: this is a non-portable compiler extension, not a part of the standard C syntax.