1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <stdint.h>
#pragma pack(1) // only matters for struct types (as far as I know)
// For this illustration, we will use sizeof(TYPE). In your code, you should use
// sizeof(EXPRESSION). Without parentheses is okay, if you're confident.
int main(int argc, char* argv[]) {
printf("sizeof(char) == %zd\n", sizeof(char));
printf("sizeof(unsigned char) == %zd\n", sizeof(unsigned char));
// ▒int▒_t types have predictable size on any platform.
printf("sizeof(uint8_t ) == %zd\n", sizeof(uint8_t )); // 8, unsigned, 0 to 255
printf("sizeof(int8_t ) == %zd\n", sizeof( int8_t )); // 8, signed, -128 to 127
printf("sizeof(uint16_t) == %zd\n", sizeof(uint16_t)); // 16, unsigned, 0 to 2¹⁶-1
printf("sizeof(int16_t) == %zd\n", sizeof( int16_t)); // 16, signed, -2¹⁵ to 2¹⁵-1
printf("sizeof(uint32_t) == %zd\n", sizeof(uint32_t)); // 32, unsigned
printf("sizeof(int32_t) == %zd\n", sizeof( int32_t)); // 32, signed
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2022 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.