Sized integer types in C
stdint.h gives you exact widths, which int and long do not promise.
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
void widths(void) {
int8_t small = -128;
uint8_t byte = 255;
int32_t medium = 2147483647;
int64_t large = 9000000000LL;
size_t count = sizeof(medium);
printf("%d %u %d\n", small, byte, medium);
printf("%" PRId64 " over %zu bytes\n", large, count);
}
How it works
int32_tanduint8_tsay exactly what they are.PRId64is the printf specifier for anint64_t.size_tis the type for sizes and array indices.
Keywords and builtins used here
int32_tint64_tint8_tsize_tsizeofuint8_tvoidwidths
The run, in numbers
- Lines
- 14
- Characters to type
- 312
- Tokens
- 75
- Three-star pace
- 80 tpm
At the three-star pace of 80 tokens a minute, this run takes about 56 seconds.
Step 4 of 7 in Variables & types, step 4 of 35 in Language basics.