MidnightRover
MidnightRover

Reputation: 197

Use of the @ symbol in C programming

I'm working with some code that was originally written for IAR and converting it to compile using the GCC compiler.

However, I'm stuck with one particular line as I don't understand the syntax or what is going on.

__root const uint32_t part_number @ ".part_number" = 701052;

The __root I've found out is so that the the variable is included in the final code even if there is nothing that actually references it. const means that it won't change and is kept in the ROM instead of RAM.

It is the @ ".part_number" part that I don't follow. The specific error I get is "stray '@' in program".

I understand that @ isn't a part of standard C, but I haven't had any luck finding anything that explains this syntax I'm seeing.

Upvotes: 9

Views: 383

Answers (1)

Matteo Italia
Matteo Italia

Reputation: 126777

From this KB entry, it looks like it's syntax to instruct the linker to place the variable into a specific section:

If you instead place the object into a named segment:

__no_init struct setup located_configuration @ "SETUP";

The equivalent GCC syntax is through the section attribute.

const uint32_t part_number __attribute__ ((section (".part_number")) = 701052;

Upvotes: 7

Related Questions