编译后结构体的大小可以改变吗?
假设您有以下结构:
#include <windows.h> // BOOL is here.
#include <stdio.h>
typedef struct {
BOOL someBool;
char someCharArray[100];
int someIntValue;
BOOL moreBools, anotherOne, yetAgain;
char someOthercharArray[23];
int otherInt;
} Test;
int main(void) {
printf("Structure size: %d, BOOL size: %d.\n", sizeof(Test), sizeof(BOOL));
}
当我在我的机器(32 位操作系统)中编译这段代码时,输出如下:
Structure size: 148, BOOL size: 4.
我想知道一旦编译,这些值是否可能会根据运行该代码的机器而改变程序。例如:如果我在 64 位机器上运行这个程序,输出会相同吗?或者一旦编译它就永远是一样的?
非常感谢您,如果这个问题的答案很明显,请原谅我......
suppose you have the following structure:
#include <windows.h> // BOOL is here.
#include <stdio.h>
typedef struct {
BOOL someBool;
char someCharArray[100];
int someIntValue;
BOOL moreBools, anotherOne, yetAgain;
char someOthercharArray[23];
int otherInt;
} Test;
int main(void) {
printf("Structure size: %d, BOOL size: %d.\n", sizeof(Test), sizeof(BOOL));
}
When I compile this piece of code in my machine (32-bit OS) the output is the following:
Structure size: 148, BOOL size: 4.
I would like to know if, once compiled, these values may change depending on the machine which runs the program. E.g.: if I ran this program in a 64-bit machine, would the output be the same? Or once it's compiled it'll always be the same?
Thank you very much, and forgive me if the answer to this question is obvious...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是固定的,一旦编译就不会改变。在 64 位计算机上,它仍将作为 32 位应用程序运行。
It is fixed and will not change once compiled. On a 64-bit machine, it will still run as a 32-bit application.
他们不会改变,除非查克·诺里斯这么说。
They won't change, unless Chuck Norris says so.