Skip to content

Commit

Permalink
Add content src/site/notes/ProgrammingLanguages/cpp/build-set/gcc/gcc…
Browse files Browse the repository at this point in the history
… attributes.md
  • Loading branch information
1024daniel committed Jun 25, 2024
1 parent 7718f3b commit 7b074b5
Showing 1 changed file with 35 additions and 0 deletions.
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
```

0 comments on commit 7b074b5

Please sign in to comment.