我正在尝试计算这个结构的字节大小,并有几个问题
struct stc {
int a;
int b;
char c;
union stc2 {
long a0;
int a1;
int a2;
};
char arr[10];
int z:2;
};
Run Code Online (Sandbox Code Playgroud)
我正在用这种方式检查大小:
int main(void) {
printf("%zu\n", sizeof(struct stc));
}
Run Code Online (Sandbox Code Playgroud)
并编译:
gcc -std=c99 -m32 -Wall -Wextra test.c
这是gcc 4.9,我在64位计算机上,但首先要尝试32位值,所以-m32.现在,结果是20,但我不知道为什么会这样.这就是我的计算方式.
struct stc {
int a; // +4 = 4
int b; // +4 = 8
char c; // +1 but next is long, so +4 (alignment) = 12
union stc2 {
long a0; // +4 = …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写我的第一个makefile.在我的项目中,我有这些文件:
其中任何一个都没有函数定义或声明,只需要简单include "list.h"干净的主要来测试编译过程.当我使用命令在控制台中编译这些文件时:
gcc -std=c99 -Wall -Wextra main.c list.c
一切都很好,但是当我使用我的Makefile(在Qt Creator和Gome终端中)时,我遇到了很多错误:
:-1: error: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11.
这是我的Makefile:
CC=gcc
CFLAGS=-std=c99 -Wall -Wextra
LDFLAGS=
all: listtest
listtest: main.o list.o
$(CC) main.o list.o -o listtest
main.o: main.c
$(CC) $(CFLAGS) main.c
list.o: list.c
$(CC) $(CFLAGS) list.c
clean:
rm -rf *o listtest
Run Code Online (Sandbox Code Playgroud)
这是我用来创建它的makefile教程.这个makefile有什么问题,如何解决?