1,防止一个头文件被重复包含 #ifndefCOMDEF_H #define COMDEF_H //头文件内容 #endif2,重新定义一些类型,防止由于各种平台和编译器的不同,而产生的类型字节数 差异,方便移植。 typedef unsigned char boolean; /* Boolean value type. */ typedef unsigned long intuint32; /* Unsigned 32 bit value */ typedefunsigned short uint16; /* Unsigned 16 bit value */ typedefunsigned char uint8; /* Unsigned 8 bit value */ typedef signed long intint32; /* Signed 32 bit value */ typedefsigned short int16; /* Signed 16 bit value */ typedefsigned char int8; /* Signed 8 bit value */ //下面的不建议使用 typedef unsigned char byte; /* Unsigned 8 bitvalue type. */ typedef unsigned short word; /* Unsinged16 bit value type. */ typedef unsigned long dword; /* Unsigned 32 bit value type. */ typedef unsignedchar uint1; /* Unsigned 8 bit value type. */ typedef unsignedshort uint2; /* Unsigned 16 bit value type. */ typedef unsignedlong uint4; /* Unsigned 32 bit value type. */ typedef signedchar int1; /* Signed 8 bit value type. */ typedef signedshort int2; /* Signed 16 bit value type. */ typedef long intint4; /* Signed 32 bit value type. */ typedefsigned long sint31; /* Signed 32 bit value */ typedefsigned short sint15; /* Signed 16 bit value */ typedefsigned char sint7; /* Signed 8 bit value */ 3,得到指定地址上的一个字节或字 #define MEM_B( x ) ( *( (byte *) (x) ) ) #define MEM_W( x ) ( *( (word *) (x) ) ) 4,求最大值和最小值 #define MAX( x, y ) ( ((x) > (y)) ? (x) : (y) ) #define MIN( x, y ) ( ((x) field ) /*lint +e545 */ 分析:#include typedef struct person { int num; int age; char name[20];}person;#defi
c语言宏定义放置位置,c语言宏定义详解
最新推荐文章于 2024-02-01 12:42:10 发布
本文详细介绍了C语言中的宏定义,包括防止头文件重复包含、类型定义、位操作、边界值计算等常见用法。并提供了示例代码,帮助理解宏定义在不同场景下的应用,提升代码的可移植性和效率。
摘要由CSDN通过智能技术生成