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)
}

全局变量地址修饰符(@address)
您可以使用全局变量地址修饰符将全局变量分配给特定地址。这些变量称为“绝对变量”。它们对于访问内存映射的I / O端口很有用,并具有以下语法:

声明= <TypeSpec> <声明符> [@ <地址> | @“ <部分>”]
[= <Initializer>];
<TypeSpec>是类型说明符,例如int,char

<Declarator>是全局对象的标识符,例如i,glob

<Address>是对象的绝对地址,例如0xff04、0x00 + 8

<Initializer>是全局变量初始化到的值。

将为每个用绝对地址指定的全局对象创建一个段。该地址不得在链接参数文件的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; //错误(对象是局部变量)
}

主要在嵌入式内应用多,将某一变量名称指向寄存器的地址处,之后对此地址处寄存器的操作(赋值)只需要对此变量名操作即可

以pic16F877A中pic16F877.h头文件对寄存器地址的命名举例

static volatile unsigned char INDF @0x00;

static volatile unsigned char TMR0 @0x01;

这里将0x00地址处赋予INDF,而INDF对应多少位呢,unsigned char限定INDF表示8位,这样就对0x00物理地址下的8位寄存器命名了一个变量,之后操作此地址下寄存器只需要操作此变量即可,不需要在记忆寄存器的地址是什么,只需要记住它对应的变量名即可,毕竟记名字要比一系列数字要好的多;

还可以使用指针符号来对某一地址下寄存器进行命名举例说明

以上面情况举例

#define INDF (static volatile unsigned char *)0x00;

将0x00强制类型转换为unsigned char 的指针类型 并对它赋予另外一个名字INDF

C语言中的 @ 符号是什么意思?的更多相关文章

  1. 【 c语言中无符号和有符号的加法运算】【深入理解】--【sky原创】

    原文:[ c语言中无符号和有符号的加法运算][深入理解]--[sky原创]   第一题 #include<stdio.h> int main() { unsigned int a=6; i ...

  2. 《C语言深度剖析》学习笔记----C语言中的符号

    本节主要讲C语言中的各种符号,包括注释符.单引号双信号以及逻辑运算符等. 一.注释符 注释符号和注释在程序的预编译期就已经被解决了,在预编译期间,编译器会将注释符号和注释符号之间的部分简单的替换成为空 ...

  3. C语言中 有符号数、无符号数、整数溢出 (转)

    #include<stdio.h> void main() { int l=-1; unsigned int c=135; printf("%u\n",l+c); } ...

  4. C语言中的符号重载

    摘自<C专家编程>第二章37页                     C语言中符号的重载 符号 意义 static 在函数内部,表示该变量的值在各个调用间一直保持延续性在函数这一级,表示 ...

  5. C语言中的符号总结

    1.注释符号                     //和/* ...*/ 2.续行符号                      \ 3.转义符号                     常用:\ ...

  6. c/c++排坑(2) -- c语言中的符号重载

    所谓的符号重载就是在不同的上下文环境里有不同的意义.甚至有些关键字也被重载而具有好几种意义,这也是C语言的作用域规则对程序员不那么清晰的主要原因. 本章内容摘自<c专家编程>P37. 大家 ...

  7. 【转】C语言中的符号优先级

    转自: http://blog.csdn.net/huangblog/article/details/8271791 虽然在日常使用中,添加括号来明确规定运算符优先级是一种常识,但毕竟学校考试就喜欢考 ...

  8. C语言中无符号与有符号问题

    unsigned char a[5] = { 12,36,96,128,182 }; a[]范围为0~256. 数组中数都有效. char a[5] = { 12,36,96,128,182 }; a ...

  9. C语言中的强符号与弱符号

    转自:http://blog.csdn.net/astrotycoon/article/details/8008629 一.概述 在C语言中,函数和初始化的全局变量(包括显示初始化为0)是强符号,未初 ...

随机推荐

  1. Oracle之查询排序

    SQL排序查询 DESC降序.ASC升序(默认是升序) /* 语法结构: SELECT * | 列名1[,列名2...] | 表达式 FROM 表名 [WHERE 限定条件] ORDER BY 列名1 ...

  2. HMS Core挑战赛故事:鞋、街景、手办、玩具,原来这些都可以3D建模

    HMS Core线上Codelabs挑战赛第3期中,开发者通过学习和运用HMS Core开发的3D建模服务,生成3D建模应用demo,再使用demo为自己身边的一个实物完成建模.在提交的作品中,小编发 ...

  3. 商城秒杀系统总结(Java)

    本文写的较为零散,对没有基础的同学不太友好. 一.秒杀系统项目总结(基础版) classpath 在.properties中时常需要读取资源,定位文件地址时经常用到classpath 类路径指的是sr ...

  4. 8.StringTable(字符串常量池)

    一.String的基本特性 String:字符串,使用一对 "" 引起来表示 String s1 = "atguigu" ; // 字面量的定义方式 Strin ...

  5. Python:matplotlib.cm 色表

    官网:Choosing Colormaps in Matplotlib - Matplotlib 3.5.0 documentation Colormap与matplotlib.cm 我们以等高区域函 ...

  6. 利用while循环写的简单小游戏猜数字

    猜数字的大小游戏 C:\Users\Administrator>python Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 23 2018, 23:31:1 ...

  7. pandas 中dataframe的操作

    先用pandas生成数据, import numpy as npimport pandas as pddf= pd.DataFrame(np.arange(30).reshape(6,5),colum ...

  8. C++_Leecode20有效的括号

    一.题目介绍 1.题目描述 给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正 ...

  9. 微信小程序两点之间的距离

    1:申请key: https://lbs.qq.com/dev/console/application/mine 网址: https://note.youdao.com/ynoteshare/inde ...

  10. NOIP集训题目解析

    11.01 子段和 题目大意 给定一个长度为 \(n\) 的序列 \(a\) ,\(a_i=\{ -1,0,1 \}\) ,需要将 \(a\) 中的 \(0\) 变为 \(1\) 或 \(-1\) , ...