-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add content src/site/notes/ProgrammingLanguages/cpp/build-set/gcc/gcc…
… attributes.md
- Loading branch information
1 parent
7718f3b
commit 7b074b5
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/site/notes/ProgrammingLanguages/cpp/build-set/gcc/gcc attributes.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
{"dg-publish":true,"permalink":"/ProgrammingLanguages/cpp/build-set/gcc/gcc attributes/","noteIcon":"3"} | ||
--- | ||
|
||
https://stackoverflow.com/questions/11770451/what-is-the-meaning-of-attribute-packed-aligned4 | ||
|
||
#gcc #attributes #cling | ||
### 1. alignment | ||
|
||
```cpp | ||
// 注意cling一行一行解析,这里对于结构体定义的大括号需要在同一行 | ||
struct sSampleStruct1 { | ||
char Data1; | ||
//3-Bytes Added here. | ||
int Data2; | ||
unsigned short Data3; | ||
char Data4; | ||
//1-byte Added here. | ||
}; | ||
|
||
struct sSampleStruct2 { | ||
char Data1; | ||
int Data2; | ||
unsigned short Data3; | ||
char Data4; | ||
|
||
}__attribute__((packed, aligned(1))); | ||
|
||
cout<<sizeof(sSampleStruct1)<<endl; // output: 12 | ||
cout<<sizeof(sSampleStruct2)<<endl; // output: 8 | ||
``` | ||