いくつかの Web サイトからコピーしたサンプル プログラムがあります。
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;
}
このプログラムを実行したところ、次のような出力が得られました。
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
64 ビット Ubuntu を実行している Linux PC でこれを実行しています。私の質問は、32 ビット マシンで同じプログラムを実行した場合、異なる結果が表示されるかどうかです。つまり、基本データのサイズはタイプは依存します
- プロセッサー
- オペレーティング·システム
- 他に何か