说明:最近学习C语言寄存器操作,读到了代码
#define STOREG(x) (*((uint16_t*)&x)
起初不理解什么意思,现在解释记录一下。
int a = 1; int *p = &a; float *p1 = (float*)p;
int a; int *p = &a; char *p1 = (char *)&a;
struct str1 a; struct str2 b; a=*((struct str1*)&b);
最后,献上我自定义的内存强制类型转换
/*
*@brief 将x强制类型转换成type类型
*@param x 待转换的变量
*@param type 将要转换的类型
*/
#define FORCE_TYPE_CONVERSION(x,type) ( *(type*)&x )
.
原文:https://www.cnblogs.com/shuoguoleilei/p/14722286.html