c语言宏定义技巧(常用宏定义)(The C language macro definition techniques (commonly used macros))
c语言宏定义技巧(常用宏定义)(The C language macro definition techniques (commonly used macros))
The C language macro definition techniques (commonly used macros)
Written in C language, beautiful macro definition is very important, the use of macro definitions can prevent errors, improve portability, readability, convenience and so on. Here are some of the mature software commonly used in macro definition......
1, to prevent a header file contains repeated
#ifndef COMDEF_H
#define COMDEF_H
The contents of the file / head
#endif
2, re define types that prevent due to a variety of platforms and compilers of different types of bytes resulting from the difference, easy to transplant.
Typedef unsigned char Boolean Boolean value type.; / * * /
Typedef unsigned long int uint32 Unsigned bit value; / * * / 32
Typedef unsigned short uint16 Unsigned bit value; / * * / 16
Typedef unsigned char uint8 Unsigned bit value; / * * / 8
Typedef signed long int int32 Signed bit value; / * * / 32
Typedef signed short int16 Signed bit value; / * * / 16
Typedef signed char int8 Signed bit value; / * * / 8
The following / / not recommended
Typedef unsigned char byte Unsigned bit value type. 8; / * * /
Typedef unsigned short word Unsinged bit value type. 16; / * * /
Typedef unsigned long DWORD Unsigned bit value type. 32; / * * /
Typedef unsigned char uint1 Unsigned bit value type. 8; / * * /
Typedef unsigned short uint2 Unsigned bit value type. 16; / * * /
Typedef unsigned long uint4 Unsigned bit value type. 32; / * * /
Typedef signed char INT1 Signed bit value type. 8; / * * /
Typedef signed short INT2 Signed bit value type. 16; / * * /
Typedef long int int4 Signed bit value type. 32; / * * /
Typedef signed long sint31 Signed bit value; / * * / 32
Typedef signed short sint15 Signed bit value; / * * / 16
Typedef signed char sint7 Signed bit value; / * * / 8
3, given a byte or word address.
#define MEM_B (x) (* ((byte *) (x)))
#define MEM_W (x) (* ((word *) (x)))
4, the maximum value and the minimum value