6713处理器,ccs3.3环境,定义的结构体里面有char,floa,double类型。在x86环境下,用pack(1)就可实现一字节对齐。那么在ccs3.3环境下,6713处理器上编程如何实现1字节结构体对齐?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
试试下面的设置( 来源文档SPRU187):
6.9.28 The STRUCT_ALIGN Pragma
The STRUCT_ALIGN pragma is similar to DATA_ALIGN, but it can be applied to a structure, union type,
or typedef and is inherited by any symbol created from that type. The STRUCT_ALIGN pragma is
supported only in C.
The syntax of the pragma is:
#pragma STRUCT_ALIGN( type , constant expression )
This pragma guarantees that the alignment of the named type or the base type of the named typedef is at
least equal to that of the expression. (The alignment may be greater as required by the compiler.) The
alignment must be a power of 2. The type must be a type or a typedef name. If a type, it must be either a
structure tag or a union tag. If a typedef, its base type must be either a structure tag or a union tag.
Since ANSI/ISO C declares that a typedef is simply an alias for a type (i.e. a struct) this pragma can be
applied to the struct, the typedef of the struct, or any typedef derived from them, and affects all aliases of
the base type.
This example aligns any st_tag structure variables on a page boundary:
typedef struct st_tag
{
int a;
short b;
} st_typedef;
#pragma STRUCT_ALIGN (st_tag, 128);
#pragma STRUCT_ALIGN (st_typedef, 128);
Any use of STRUCT_ALIGN with a basic type (int, short, float) or a variable results in an error.
可以试下如下方式实现结构体中成员1byte对齐
struct __attribute__((__packed__)) packed_struct { char c1; int i; char c2; };