-
-
Save jeffs/a14072313400f3eb9753ff2f6b76bbf6 to your computer and use it in GitHub Desktop.
nested-type-alignment-c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
struct CStruct { | |
int16_t a; // 2 bytes | |
int32_t b; // 4 bytes | |
int16_t c; // 2 bytes | |
int32_t d; // 4 bytes | |
}; | |
int main() { | |
puts("C struct:\n"); | |
printf(" offset of a: %2ld bytes\n", offsetof(struct CStruct, a)); | |
printf(" offset of b: %2ld bytes\n", offsetof(struct CStruct, b)); | |
printf(" offset of c: %2ld bytes\n", offsetof(struct CStruct, c)); | |
printf(" offset of d: %2ld bytes\n", offsetof(struct CStruct, d)); | |
printf(" total size: %2ld bytes\n", sizeof(struct CStruct)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment