提交 e54a610a 编写于 作者: F feilong

add stucture pack

上级 2701e88a
# 数的结构判断
假设机器字是8 bytes,下面代码的占据的内存大小是多大?
```c
struct Test{
char *p;
char c;
int x;
}
```
更多知识请参考:[失传的C结构体打包技艺](https://github.com/ludx/The-Lost-Art-of-C-Structure-Packing)
## template
```c
struct Test{
char *p;
char c;
int x;
};
int main(int argc, char**){
print("%d", sizeof(struct Test))
return 0;
}
```
## 答案
```c
8 bytes
```
## 选项
### 选项1
```c
6 bytes
```
### 选项2
```c
9 bytes
```
### 选项3
```c
24 bytes
```
\ No newline at end of file
......@@ -182,7 +182,14 @@ void sha256_read_hex(const struct sha256_buff *buff, char *hex) {
}
int main(int argc, char **argv) {
FILE *file = fopen(argv[1], "rb");
FILE *f1 = fopen("/tmp/c_hash_test.txt", "w+");
for (int i = 0; i < 1024; i++) {
fputs("Hello,World!", f1);
}
fclose(f1);
FILE *file = fopen("/tmp/c_hash_test.txt", "rb");
if (!file) {
printf("Cannot open file\n");
return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册