The __align keyword instructs the compiler to align a variable on an n-byte boundary.
__align is a storage class modifier. It does not affect the type of the function.
Syntax
__align(n)
Where:
n
is the alignment boundary.
For local variables, n can take the values 1, 2, 4, or 8.
For global variables, n can take any value up to 0x80000000 in powers of 2.
Usage
__align(n) is useful when the normal alignment of the variable being declared is less than n. Eight-byte alignment can give a significant performance advantage with VFP instructions.
__align can be used in conjunction with extern and static.
Restrictions
Because __align is a storage class modifier, it cannot be used on:
Types, including typedefs and structure definitions.
Function parameters.
You can only overalign. That is, you can make a two-byte object four-byte aligned but you cannot align a four-byte object at 2 bytes.
Example
__align(8) char buffer[128]; // buffer starts on eight-byte boundary
void foo(void)
{
...
__align(16) int i; // this alignment value is not permitted for
// a local variable
...
}
__align(16) int i; // permitted as a global variable.
那么问题来了;这里是这样描述的__align(n) is useful when the normal alignment of the variable being declared is less than n.大概意思是说如果之前的边界对齐大小小于要声明的才需要使用,但是我追踪这里的代码 #define __ALIGN_BEGIN __align(4) 意思是以4字节对齐,但是这个结构体中全部都是1个字节的元素,请问怎么理解?
评分
查看全部评分
评分
查看全部评分
英文太差怎么办
随便百度一下__align吧。。。
那么问题来了;这里是这样描述的__align(n) is useful when the normal alignment of the variable being declared is less than n.大概意思是说如果之前的边界对齐大小小于要声明的才需要使用,但是我追踪这里的代码 #define __ALIGN_BEGIN __align(4) 意思是以4字节对齐,但是这个结构体中全部都是1个字节的元素,请问怎么理解?
而且32位MCU默认就是4字节对齐吧,这里没必要再声明一次啊,也许我理解错误,望大神指正
这个4字节对齐是在某种模式下强制使用的,你看下是不是你的USB工作在HS或者启动了DMA.