Mindestgröße von unsigned long



  • Hi,

    bisher bin ich von folgendem ausgegangen:

    (unsigned) char = 1 Byte <= (unsigned) short <= (unsigned) int <= (unsigned) long

    d.h. dass long auch theoretisch ein Byte groß sein kann. In comp.lang.c++ wird mir aber widersprochen. Dazu folgendes:

    §3.9.1 schrieb:

    2. There are four signed integer types: "signed char", "short int", "int", and "long int". In this list, each type provides at least as much storage as those preceding it in the list. Plain ints have the natural size suggested by the architecture of the execurtion environment (that is, large enough to contain any value in the range of INT_MIN and INT_MAX, as defined in the header <climits>); the other signed integer types are provided to meet special needs.

    3. For each of the signed integer types, there exists a corresponding (but different) unsigned integer rype: "unsigned char", "unsigned short int", "unsigned int", and "unsigned long int," each of which occupies the same amount of storage and has the same alignment requirements (3.9) as the corresponding signed integer type; [...]

    Nun heißt es, dass vom C90-Standard geerbt wurde, dass int >= 16 Bit und long >= 32 Bit sein muss. Stimmt das so?



  • Für (u.a.) int und long sind im Standardmindestwertebereiche angegeben, die auf 16bit bzw. 32bit hinauslaufen. Wahrscheinlich in C90, bin mir nicht sicher, aber das gilt ja auch für C++.



  • Hat eine Maschine z.B. 32-Bit-Bytes, dann duerfen laut C/C++-Standard sizeof(short), sizeof(int) und sizeof(long) jeweils 1 zurueckliefern, da die Mindestgroesse von char 8 Bit, von short 16 Bit, von int 16 Bit, und von long 32 Bit ist.

    sizeof(long long) wuerde auf so einer Maschine 2 zurueckliefern, wuerde also zwei aus 32-Bit-Bytes bestehen.

    Dies kommt vor allem bei virtuellen Maschinen vor, die mit fester Wortbreite arbeiten (z.B. 32 Bit).

    Die INTCODE-Maschine von Martin Richards waere so ein Beispiel, das mit fester Wortbreite beliebiger Groesse arbeitet (mind. 16 Bit, oft 32 Bit). Da die Maschine wortadressiert ist, kann man immer nur auf ganze Woerter zugreifen.

    Es gibt auch reale, wortadressierte Computer, bei denen das auch zutrifft.


Anmelden zum Antworten