Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of @ symbol in c programing?

Tags:

c

I'm working with some code that was originally written for IAR and converting it to compile using a 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.

If anyone is able to explain it, I would really appreciate it.

Thanks

like image 565
MidnightRover Avatar asked Dec 12 '17 23:12

MidnightRover


1 Answers

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;
like image 85
Matteo Italia Avatar answered Oct 20 '22 00:10

Matteo Italia