How do I place a group of variables in a specific section in gcc, is there anything like #pragma default_variable_attributes available with arm

廉价感情. 提交于 2021-02-20 02:08:10

问题


The below link https://www.iar.com/support/tech-notes/linker/how-do-i-place-a-group-of-functions-or-variables-in-a-specific-section/ explains how a group of variables can be placed in a specific section, this is with IAR arm linker.

Pasting the example (for which i want a gcc equivalent) from the link here

/* Place following data in section MY_DATA */
#pragma default_variable_attributes = @ "MY_DATA"

int data1;
int data2;

/* Stop placing data in section MY_DATA */
#pragma default_variable_attributes =

In gcc do we have any such feature, which helps me to define in the source code how the variables can be place contiguously.

Regards


回答1:


With gcc you use the compiler's __attribute__ extension of the declarator syntax, e.g.

int my_global_1 __attribute__ ((section ("MyData"))) = 0;
int my_global_2 __attribute__ ((section ("MyData"))) = 0;

__attribute__ ((section ("MyFuncs"))) int foo(int i) 
{
    return i * i;
}


来源:https://stackoverflow.com/questions/34638115/how-do-i-place-a-group-of-variables-in-a-specific-section-in-gcc-is-there-anyth

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!