在ccs3.3.82.13 版中
#define PACKED __attribute__ ((packed))
typedef struct
{
char a;
int b;
}
PACKED testStruct;
编译出错: error: expected a type specifier
error: expected a ";"
Phyllis Xu:
你好!
编译错误是因为应该在结构体类型定义后,即大括号后加上类型定义名和分号。
谢谢!
dsp china:
回复 Phyllis Xu:
typedef struct
{
char a;
int b;
}
testStruct;
这样定义肯定是没有问题的,但是我不要4字节对齐啊,sizeof(testStruct) = 8;实际上我要的是sizeof(testStruct) = 5才对,也就是说VC里定义#pragma pack(push,1)一样,要1个字节对齐,#define PACKED __attribute__ ((packed))的目的就是要1个字节对齐,但在ccs3.3中就无法使用,不知到是不是ccs3.3不支持?ccs5就OK
Jason Wang83:
这里是一种标准写法,你可以参考一下:
typedef struct tnode { /* the tree node: */
char *word; /* points to the text */
int count; /* number of occurrences */
struct tnode *left; /* left child */
struct tnode *right; /* right child */
} Treenode;
pentz woods:
回复 Jason Wang83:
感觉你有点儿答非所问,他问的是字节对齐的问题,而不是结构体类型自定义的问题
TI中文支持网
