DATA_SECTION pragma

来源:互联网 发布:淘宝被加黑名单怎么查 编辑:程序博客网 时间:2024/05/16 11:30
ti的帮助文档里是这么讲的:

The DATA_SECTION pragma allocates space for the symbol in a section called section name.
The syntax for the pragma in C is:

#pragma DATA_SECTION (symbol, "section name");

The syntax for the pragma in C++ is:

#pragma DATA_SECTION ( "section name");

The DATA_SECTION pragma is useful if you have data objects that you want to link into an area separate from the .bss section.
This directive is illustrated in the following example.

Using the DATA_SECTION Pragma

a)  C source file

#pragma DATA_SECTION(bufferB, "my_sect")
char bufferA[512];
char bufferB[512]:

b)  C++ source file

char bufferA[512];
#pragma DATA_SECTION("my_sect")
char bufferB[512];

c)  Assembly source file

          .global _bufferA
          .bss    _bufferA,512,4
          .global _bufferB
_bufferB: .usect  "my_sect",512,4


我理解的意思是:
  定义一个数据段: 
          段名为:    "section name"
          段的内容在:  symbol  里
在CCS编程中,如果我们不指定变量的存放位置,编译器会自动的给变量分配一个位置,但是如果有的时候需要把变量放在一个特定的空间内,我们应该如何操作呢,CCS提供了如下的两个指令
#pragma CODE_SECTION
#pragma DATA_SECTION
其中data_section是针对数据空间的,code_section是针对程序空间的,具体的使用办法是
#pragma DATA_SECTION(bufferB, ”my_sect”)
char bufferB[512];
在.cmd文件中建立对应的section就可以使用了.

MEMORY
{
PAGE 1: spacename : origin = 0x...., length 0x..
}
SECTIONS
{
    .my_sect  : {} >spacename PAGE 1
}