我有一个示例程序,我从一些网站复制.
int main(void)
{
int answer;
short x = 1;
long y = 2;
float u = 3.0;
double v = 4.4;
long double w = 5.54;
char c = 'p';
typedef enum
{
kAttributeInvalid,
kBooleanAttributeActive,
kBooleanAttributeAlarmSignal,
kBooleanAttributeAlign64,
kBooleanAttributeAutoNegotiationComplete,
}codes_t;
/* __DATE__, __TIME__, __FILE__, __LINE__ are predefined symbols */
#if 0
printf("Date : %s\n", __DATE__);
printf("Time : %s\n", __TIME__);
printf("File : %s\n", __FILE__);
printf("Line : %d\n", __LINE__);
#endif
/* The size of various types */
printf("The size of int %zu\n", sizeof(answer));
printf("The size of short %zu\n", sizeof(x));
printf("The size of long %zu\n", sizeof(y));
printf("The size of float %zu\n", sizeof(u));
printf("The size of double %zu\n", sizeof(v));
printf("The size of long double %zu\n", sizeof(w));
printf("The size of char %zu\n", sizeof(c));
printf("The size of enum %zu\n", sizeof(codes_t));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我运行这个程序,我得到的输出如下.
The size of int 4
The size of short 2
The size of long 8
The size of float 4
The size of double 8
The size of long double 16
The size of char 1
The size of enum 4
Run Code Online (Sandbox Code Playgroud)
我在运行64位Ubuntu的Linux PC上运行它.我的问题是,如果我在32位机器上运行相同的程序,我会看到不同的结果.或者换句话说,基本数据的大小类型取决于
小智 7
我的问题是,如果我在32位机器上运行相同的程序,我会看到不同的结果
也许.或者可能不是.
或者换句话说,基本数据类型的大小取决于1)处理器2)操作系统3)其他任何东西
"而你的编译器标志......"(谢谢,凯!)
| 归档时间: |
|
| 查看次数: |
21994 次 |
| 最近记录: |