C语言中的 @ 符号
2017-07-10 12:17
561 查看
看到一段程序自动生成的嵌入式C语言代码,
在.c文件中是这样调用的,
/* PTASE: PTASE1=1,PTASE0=1 */
PTASE |= (unsigned char)0x03;
在.h文件中是这样定义的,先定义了一个结构体
/*** PTASE - Slew Rate Control Enable for Port A; 0x00001841 ***/
typedef union {
byte Byte;
struct {
byte PTASE0 :1; /* Slew Rate Control Enable for Port A Bit 0 */
byte PTASE1 :1; /* Slew Rate Control Enable for Port A Bit 1 */
byte PTASE2 :1; /* Slew Rate Control Enable for Port A Bit 2 */
byte PTASE3 :1; /* Slew Rate Control Enable for Port A Bit 3 */
byte PTASE4 :1; /* Slew Rate Control Enable for Port A Bit 4 */
byte PTASE5 :1; /* Slew Rate Control Enable for Port A Bit 5 */
byte PTASE6 :1; /* Slew Rate Control Enable for Port A Bit 6 */
byte PTASE7 :1; /* Slew Rate Control Enable for Port A Bit 7 */
} Bits;
} PTASESTR;
这下面一句中的@符合到底代表什么意思?应该是定义一个结构体变量,然后这个变量是指向0x00001841地址的
extern volatile PTASESTR _PTASE @0x00001841;
#define PTASE _PTASE.Byte
并宏定义了指向结构体变量
我想问的是@符合到底是什么意思?或哪里有@符号的详细解释,Thanks
是不是从某个地址开始的意思?
嗯,肯定是这意思,不过想知道关于@的详细说明,好像找到了,我用的是Codewarrior,手册上好像写了,我把贴上来
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 = <TypeSpec> <Declarator>[@<Address>|@"<Section>"]
[= <Initializer>];
<TypeSpec> is the type specifier, e.g., int, char
<Declarator> is the identifier of the global object, e.g., i, glob
<Address> is the absolute address of the object, e.g., 0xff04, 0x00+8
<Initializer> 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] <segment_name>
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
<segment_name> INTO READ_ONLY <Address> ;
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)
}
http://bbs.csdn.net/topics/90243450
在.c文件中是这样调用的,
/* PTASE: PTASE1=1,PTASE0=1 */
PTASE |= (unsigned char)0x03;
在.h文件中是这样定义的,先定义了一个结构体
/*** PTASE - Slew Rate Control Enable for Port A; 0x00001841 ***/
typedef union {
byte Byte;
struct {
byte PTASE0 :1; /* Slew Rate Control Enable for Port A Bit 0 */
byte PTASE1 :1; /* Slew Rate Control Enable for Port A Bit 1 */
byte PTASE2 :1; /* Slew Rate Control Enable for Port A Bit 2 */
byte PTASE3 :1; /* Slew Rate Control Enable for Port A Bit 3 */
byte PTASE4 :1; /* Slew Rate Control Enable for Port A Bit 4 */
byte PTASE5 :1; /* Slew Rate Control Enable for Port A Bit 5 */
byte PTASE6 :1; /* Slew Rate Control Enable for Port A Bit 6 */
byte PTASE7 :1; /* Slew Rate Control Enable for Port A Bit 7 */
} Bits;
} PTASESTR;
这下面一句中的@符合到底代表什么意思?应该是定义一个结构体变量,然后这个变量是指向0x00001841地址的
extern volatile PTASESTR _PTASE @0x00001841;
#define PTASE _PTASE.Byte
并宏定义了指向结构体变量
我想问的是@符合到底是什么意思?或哪里有@符号的详细解释,Thanks
是不是从某个地址开始的意思?
嗯,肯定是这意思,不过想知道关于@的详细说明,好像找到了,我用的是Codewarrior,手册上好像写了,我把贴上来
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 = <TypeSpec> <Declarator>[@<Address>|@"<Section>"]
[= <Initializer>];
<TypeSpec> is the type specifier, e.g., int, char
<Declarator> is the identifier of the global object, e.g., i, glob
<Address> is the absolute address of the object, e.g., 0xff04, 0x00+8
<Initializer> 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] <segment_name>
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
<segment_name> INTO READ_ONLY <Address> ;
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)
}
http://bbs.csdn.net/topics/90243450
相关文章推荐
- C语言引用连接脚本lds中的符号——清除bss段,c实现方式
- 【C语言学习趣事】_33_关于C语言和C++语言中的取余数(求模)的计算_有符号和无符号数的相互转换问题
- 如何只打印中间的符号(c语言)
- C语言中的符号重载
- C语言之将无符号字符型转化为ascii码值
- C语言中符号的优先级-摘录
- C语言预处理功能 关于字符串化和符号粘贴
- C语言如何判断中文符号(简单和原理包中文括编码大全和中文符号)
- c语言 int 型 无符号数 %u
- C语言中的无符号数与有符号数混合运算时隐含转换问题
- 20170131C语言提升04_符号
- C语言symlink()函数:建立文件符号连接
- C语言中的强符号与弱符号
- (转载)C语言中strlen()返回值类型为无符号数
- c语言有符号数取值范围
- VC环境中C语言输出特殊符号
- C语言中无符号数和有符号数相加问题 .
- C语言中的有符号数与无符号数
- C语言中的取模符号讨论
- C语言符号