- __attrubte__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐。
#define __u8 unsigned char
#define __u16 unsigned short
/* __attribute__ ((packed)) 的位置约束是放于声明的尾部“;”之前 */
struct str_struct{
__u8 a;
__u8 b;
__u8 c;
__u16 d;
} __attribute__ ((packed));
- math.h的编译位图
在编译包含math.h中的函数接口时,经常为报错:undefined reference to `pow'。
原因是连接问题。
解决方法:编译时,添加参数:-lm