C语言中_at_的用法

Python08

C语言中_at_的用法,第1张

不是通用的C语言。Cx51

支持

_at_.

手册上有例子:

struct

link

{

struct

link

idata

*next

char

code

*test

}

//

下面4行给了地址,主程序里赋值。

struct

link

idata

list

_at_

0x40

/*

list

at

idata

0x40

*/

char

xdata

text[256]

_at_

0xE000

/*

array

at

xdata

0xE000

*/

int

xdata

i1

_at_

0x8000

/*

int

at

xdata

0x8000

*/

char

far

ftext[256]

_at_

0x02E000

/*

array

at

xdata

0x03E000

*/

void

main

(

void

)

{

link.next

=

(void

*)

0

i1

=

0x1234

text

[0]

=

'a'

ftext[0]

=

'f'

}

_at_ 并非C语言的普通语法,而是Cx51特有的语法,属于嵌入式C的关键字,用于将特定变量存放在指定的绝对地址中。这句话有两个词语要格外注意:

1、变量:即函数和位变量不能定义在绝对地址;

2、绝对地址:要考虑你的物理内存到底有多大,要符合实际情况,不能超出实际边界。

接下来回答你的两个问题:

1、是的。

2、不是,port++到底加了多少,要由port是什么类型的指针来决定。以32位系统举例,如果是

int *port

那么port++将自增4个字节。如果是double *port那么port++将自增8个字节。

你的是uchar data *port不知道port是什么类型的指针,所以加多少我不知道。