keil mdk + stm32 bytes in the two compilers ac6 ac5 and alignment operation method

Recently the use of ac6.9 compiler, compilation speed is really fast, using the hal stm32 library compilation speed is much faster than the compiler ac5.
Test herein stm32 byte aligned code tests, the structure is mainly because the actual structure of the most used items, printed simultaneously in a simulation environment.

ac5 test results:

CC_ARM_AC5 #ifdef 
// this embodiment except ac5 compiler, 1, the length of the structural body structure not aligned manner, is the length of each of the variables and 
the __packed _li_st typedef struct 
{ 
	uint8_t A; // 1 th 
	uint16_t b; // 2 a 
	uint32_t c; // 4 months 
	uint64_t d; // 8 months         
} li_st; 

structure // ac5 compiler 2 are not aligned manner, the length of the structure, and that the length of each variable 
typedef struct _li_st_2 
{ 
	uint8_t a; @ 1 
	uint16_t b; // 2 th 
	uint32_t c; // 4 th 
	uint64_t d; // 8 th         
} attribute __ __ ((__ packed__)) li_st_2; 

//) to 4 bytes, aligned to the same 8-byte can specify . 
struct student_4B typedef 
{ 
    char name [. 7]; // +. 1 =. 8. 7 
    uint32_t ID; //. 4 
    char Subject [. 5]; // +. 3 =. 8. 5 
} __attribute __ ((the aligned (. 4))) li_st_4B;

#pragma pack (1) / * specified as * 1 byte alignment. 3 / 
typedef struct _li_st_1B 
{ 
	uint8_t A; // 1 th 
	uint16_t b; // 2 th 
	uint32_t c; // 4 th 
	uint64_t d; // 8 th         
li_st_1B}; 
#pragma Pack () / * unassign aligned, restore the default alignment * / 

#pragma Pack (2) / 2 * specified by the byte alignment * / 
typedef struct _li_st_2B 
{ 
     char B; 
     int A; 
     Short C; 
} li_st_2B; 
#pragma Pack () / * unassign aligned, restore the default alignment * /

Test results are as follows:

 

 ac6 test results:

#elif (CC_ARM_AC6)

//ac6 ac5通用,的结构体不对齐方式,结构体的长度,就是各个变量长度的和
typedef  struct _li_st_ac6
{
	uint8_t a;   //1个
	uint16_t b; //2个
	uint32_t c; //4个
	uint64_t d; //8个        
}__attribute__((packed)) li_st_ac6  ;

//ac6 ac5通用,的结构体不对齐方式2,结构体的长度,就是各个变量长度的和
#pragma pack (1) /*指定按1字节对齐*/
typedef  struct _li_st_ac6_1B 
{
	uint8_t a;   //1个
	uint16_t b; //2个
	uint32_t c; //4个
	uint64_t d; //8个        
}li_st_ac6_1B;
#pragma pack () /*取消指定对齐,恢复缺省对齐*/


//ac6 ac5通用,下面的定义和8字节一样的大小,主要看内存分布
#pragma pack (4) /*指定按4字节对齐*/
typedef  struct _li_st_ac6_4B 
{
	uint8_t a;   //1个 + 1
	uint16_t b; //2个 
	uint32_t c; //4个
	uint64_t d; //8个        
}li_st_ac6_4B;
#pragma pack () /*取消指定对齐,恢复缺省对齐*/

 

Guess you like

Origin www.cnblogs.com/CodeWorkerLiMing/p/12076701.html