Größe short, int, long, float, double long, double, char

Ich möchte herausfinden, die (short /int /long /float /double /long double /char) Größe, so schrieb ich diesen code:

printf("short\t\t%d\n", sizeof(short));    
printf("int\t\t%d\n", sizeof(int));
printf("long\t\t%d\n", sizeof(long));
printf("float\t\t%d\n", sizeof(float));
printf("double\t\t%d\n", sizeof(double));  
printf("long double\t%d\n", sizeof(long double));    
printf("char\t\t%d\n", sizeof(char));   

ABER
die Ausgabe ist:

type            bytes
short           512
int             512
long            1024
float           1024
double          1024
long double     1024
char            256

Warum sind die Anzahl der bytes, die so groß ist?

Sollte es nicht sein 2, 8, ...?

Sie haben Recht, es sollten in der Regel... was ist der Kontext, in dem Sie ausgeführt werden diese? zunächst Sprache (vorausgesetzt, C), compiler, hardware, etc.
Das ist seltsam. Was OS, compiler, etc?
Für was es Wert ist, alles immer Links verschoben um 8 bits...
sizeof gibt eine size_t, nicht ein int. So %d ist nicht angemessen.
Mit %d drucken size_t keine implizite Konvertierung von size_t zu int. Am besten, Sie interpretiert die bytes einer size_t als int. Im schlimmsten Fall, es bolluxes dem Stapel, weil die Plattform ABI wurde verletzt, was dazu führen kann weitere Fehlverhalten durch ein Programm, einen sofortigen Absturz, oder anderen unerwünschten Effekten.

InformationsquelleAutor | 2013-09-20

Schreibe einen Kommentar