frage zu sizeof(struct )
-
hallo forum
habe frage zu sizeof(). Dazu erstmal der untere text
struct info { int a; char b[0]; }; int main() { printf("%i",sizeof(int)); //ergebnis 4 Byte printf("%i",sizeof(char)) //1 Byte printf("%i",sizeof(struct info)); //4 return (0); }
warum 4 Byte wird 1 Byte (char aus struct) nicht zu 4 Byte addiert?
-
char[0] hat 0 groesse.
mit null-laenge arrays in structs kannst du header fuer sachen basteln (ip/tcp/udp, ...)
-
*zu langsam*
-
Man sollte noch erwähnen, dass zero-sized arrays nicht standardkonform sind. Besser wären da flexible array members:
struct info { int a; char b[]; };