c语⾔全局变量符号,C语⾔中的@符号是什么意思?
标签:assign inter res ted 访问内存 变量 出现 read_only his
Global Variable Address Modifier (@address)
You can assign global variables to specific addresses with the global variable address modifier. These variables are called
‘absolute variables‘. They are useful for accessing memory mapped I/O ports and have the following syntax:
Declaration = [@|@""]
[= ];
is the type specifier, e.g., int, char
is the identifier of the global object, e.g., i, glob
is the absolute address of the object, e.g., 0xff04, 0x00+8
is the value to which the global variable is initialized.
A segment is created for each global object specified with an absolute address. This address must not be inside any
address range in the SECTIONS entries of the link parameter file. Otherwise, there would be a linker error (overlapping segments). If the specified address has a size greater than that used for addressing the default data page, pointers pointing to this global variable must be "__far". An alternate way to assign global variables to specific addresses is (Listing 8.8).
Listing 8.8 Assigning global variables to specific addresses
#pragma DATA_SEG [__SHORT_SEG] setting the PLACEMENT section in the linker parameter file. An older method of accomplishing this is shown in Listing 8.9.
Listing 8.9 Another means of assigning global variables to specific addresses
INTO READ_ONLY ;
Listing 8.10 is a correct and incorrect example of using the global variable address modifier and Listing 8.11 is a possible PRM file that corresponds with example Listing.
Listing 8.10 Using the global variable address modifier
//看这意思,就是把int型变量glob地址从0x0500开始,并把值10初始化时放在0x0500
int glob @0x0500 = 10; // OK, global variable "glob" is
// at 0x0500, initialized with 10
void g() @0x40c0; // error (the object is a function)
void f() {
int i @0x40cc; // error (the object is a local variable)
}
全局变量地址修饰符(@address)
您可以使⽤全局变量地址修饰符将全局变量分配给特定地址。这些变量称为“绝对变量”。它们对于访问内存映射的I / O端⼝很有⽤,并具有以下语法:
声明= [@ | @“ ”]
[= ];
是类型说明符,例如int,char
是全局对象的标识符,例如i,glob
是对象的绝对地址,例如0xff04、0x00 + 8
是全局变量初始化到的值。
将为每个⽤绝对地址指定的全局对象创建⼀个段。该地址不得在链接参数⽂件的SECTIONS条⽬中的任何地址范围内。否则,将出现链接器错误(重叠段)。如果指定的地址的⼤⼩⼤于⽤于寻址默认数据页的⼤⼩,则指向此全局变量的指针必须为“ __far”。将全局变量分配给特定地址的另⼀种⽅法是(清单8.8)。
清单8.8将全局变量分配给特定地址
#pragma DATA_SEG [__SHORT_SEG]
在链接器参数⽂件中设置PLACEMENT部分。清单8.9显⽰了完成此操作的较旧⽅法。
清单8.9将全局变量分配给特定地址的另⼀种⽅法
INTO READ_ONLY ;
清单8.10是使⽤全局变量地址修饰符的正确和不正确的⽰例,清单8.11是与⽰例清单相对应的可能的PRM⽂件。
清单8.10使⽤全局变量地址修饰符
//看这意味着,就是把int型变量glob地址从0x0500开始,并把值10初始化时放在0x0500
int glob @ 0x0500 = 10; //确定,全局变量“ glob”为
//在0x0500处,以10初始化
⽆效g()@ 0x40c0; //错误(对象是⼀个函数)
⽆效f(){
int我@ 0x40cc; //错误(对象是局部变量)
嵌入式系统是什么意思}
主要在嵌⼊式内应⽤多,将某⼀变量名称指向寄存器的地址处,之后对此地址处寄存器的操作(赋值)只需要对此变量名操作即可
C语⾔中的 @ 符号是什么意思?
标签:assign inter res ted 访问内存 变量 出现 read_only his
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论