#pragma pack will nicht richtig
-
Hi,
irgendwie geht #pragma pack bei mir nicht so richtig, weiß jemand wo der fehler liegt?
#include <stdio.h> #include <conio.h> #pragma pack (push) struct struct1 { unsigned short f : 6; unsigned short b : 6; unsigned short c : 1; unsigned short r : 3; }; #pragma pack (pop) struct struct2 { unsigned short f : 6; unsigned short b : 6; unsigned short c : 1; unsigned short r : 3; }; int main (void) { printf ("%d\n", sizeof (struct1)); // soll 2 ausgeben, gibt 2 aus printf ("%d\n", sizeof (struct2)); // soll 4 ausgeben, gibt 2 aus printf ("%d\n", sizeof (unsigned short)); // soll 2 ausgeben, gibt 2 aus _getch (); return 0; }
-
fenriswolf schrieb:
Hi,
irgendwie geht #pragma pack bei mir nicht so richtig, weiß jemand wo der fehler liegt?
printf ("%d\n", sizeof (struct2)); // soll 4 ausgeben, gibt 2 ausVerstehe nicht, wo liegt das Problem? 2 Byte Größe sehen doch völlig richtig aus.
Normalerweise wird pragma pack auch eher für sowas verwendet:// Mit Packen ist's 5 Bytes groß, sonst 8 Bytes. struct A { int a; char c; };
-
#include <stdio.h> #include <conio.h> #pragma pack (push) #pragma pack(1) // <!--- boing struct struct1 { unsigned short f : 6; unsigned short b : 6; unsigned short c : 1; unsigned short r : 3; }; #pragma pack (pop)