Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notation __no_init __root C

Tags:

c

variables

Hello guys I was reading a C source and I found a notation like this:

__no_init __root extern volatile unsigned char var[10]    @ 0x4000000;

But I've no idea what that __no_init __root means, is it standard C?

Thank you.

like image 656
alkz Avatar asked Dec 20 '11 17:12

alkz


2 Answers

These are C language extensions used in some compilers targeting embedded systems (for example, IAR's AVR compiler).

__no_init would mean that the compiler should not initialize the variable, and would be used when a variable is placed at a hardware register location and you don't want the start-up of the program to set the register to 0.

__root is used to tell the compiler/linker that the variable or function should be kept in the binary image even if it isn't actually used in the program. This might be useful for debugging purposes and to 'size' a program while development is in progress.

like image 129
Michael Burr Avatar answered Nov 02 '22 12:11

Michael Burr


These are macros that are likely defined inside your compiler toolchain. In my experience, __no_init usually means to tell the linker that the memory for this variable should not be initialized by the crt0 startup code that normally writes zero to global variables before main is called. __root often means that the linker should not discard the variable even if it thinks no code is using it.

like image 42
TJD Avatar answered Nov 02 '22 12:11

TJD