c - Type casting to pointer, precedence with addition
问题描述
#define GPIO_BASE 0x40020000
#define GPIO_MEM_SIZE 0x0400
Those are the macro definitions which will be related.
GPIO_Type
is just a typedef struct I did.
volatile GPIO_Type *GPIOB = (GPIO_Type*) (GPIO_BASE + GPIO_MEM_SIZE);
This is fine, I am casting summation of two integers to the type of pointer I am defining.
If I do it as,
volatile GPIO_Type *GPIOB = GPIO_BASE + GPIO_MEM_SIZE;
Compiler gives a warning about "conversion from integer to pointer without casting". I understand this.
However, when I do,
volatile GPIO_Type *GPIOB = (GPIO_Type*) GPIO_BASE + GPIO_MEM_SIZE;
It(compiler) does not give a warning or error, but I know that type casting has higher precedence than addition, so it((GPIO_Type*)
) does not include GPIO_MEM_SIZE
, which is an integer.
So, why it is working without any problem? Does the compiler automatically cast GPIO_MEM_SIZE
also?
解决方案
推荐阅读
- authorization - 为什么 Envoy ext-authz 不遵守 connect_timeout?
- javascript - Jest spyOn 使函数“未定义”
- javascript - 表单提交后如何在html中使文本字段不可编辑
- java - Box2D通过加速、匀速移动和最后减速移动到目的地
- android - 如何对像whatsapp这样的android通知进行分组?因为 setGroup 不适合我
- java - SOAP Post 适用于 Postman,但不适用于 Java
- c# - 从 .net core web api 中的 Helper 类访问 HttpContextAccessor
- github - 致命:不支持协议“git@https”
- excel - 无法从包含数据的工作表中查找最后一列
- java - 如何在 Windows 64 位操作系统中安装 openJdk 8