c - 为什么 Linux 和 Windows 之间的 long 和 long double 类型大小不同?
问题描述
我现在正在学习计算机体系结构。为什么 Linux 和 Windows 操作系统之间的数据类型大小不同?
这是我的示例 C 代码。
#include<stdio.h>
int main(void)
{
printf ("\n-- General Data Type Size --\n");
printf ("char size : %d byte\n", (int)sizeof(char));
printf ("short size : %d byte\n", (int)sizeof(short));
printf ("int size : %d byte\n", (int)sizeof(int));
printf ("long size : %d byte\n", (int)sizeof(long));
printf ("double size : %d byte\n", (int)sizeof(double));
printf ("long double size : %d byte\n", (int)sizeof(long double));
printf ("\n-- Pointer Data Type Size -- \n");
printf ("char* size : %d byte\n", (int)sizeof(char*));
printf ("short* size : %d byte\n", (int)sizeof(short*));
printf ("int* size : %d byte\n", (int)sizeof(int*));
printf ("long* size : %d byte\n", (int)sizeof(long*));
printf ("double* size : %d byte\n", (int)sizeof(double*));
printf ("long double* size : %d byte\n", (int)sizeof(long double*));
return 0;
}
当我使用visual studio 10在windwos 10 64bit上编译并运行此代码时,它显示如下:
然后,当我在我的 ubuntu 18.04 64 位上编译并运行这段代码时。它显示如下:
Windows 系统显示 long double 的大小为 8 字节,long 为 4 字节。
但是 Ubuntu 向我显示 long double 的大小是 16 字节,而 long 是 8 字节。为什么两个尺寸不一样?两者都有 64 位环境,我想知道为什么它们有不同的值。如果您能解释一下,我将不胜感激。
解决方案
推荐阅读
- javascript - ReactJS:渲染 100 个 div 而不会出现任何渲染问题
- c# - 使用 HttpOnly cookie 的 JWT 授权
- algorithm - 分区问题动态规划的替代方案
- .net-core - 不同版本的 Newtonsoft.Json 之间的冲突
- python - 在 python 中使用两个列表创建字典
- swift - 传递给泛型函数时如何访问@Published 属性的包装值
- java - 如何修复在空对象引用上调用虚拟方法 'android.view.View androidx.fragment.app.FragmentActivity.findViewById(int)' 的尝试?
- javascript - 如何阻止简单的 Discord 机器人 ping 用户?
- javascript - javascript transitionEnd 在 setInterval 一段时间后不起作用
- php - 如何根据字段在多个列表中显示查询结果?