Fixed-width types
Fixed-width integers, inttypes formats, a struct shorthand and gcd.
+ <stdio.h>
+ <stdint.h>
+ <inttypes.h>
s Pair a,b:int
f gcd(a: u32, b: u32) u32
< b ? gcd(b, a % b) : a
f main()
p: Pair = {84, 36}
small: uint8_t = 200
big: int64_t = INT64_C(1) << 40
printf("gcd %d %d = %u\n", p.a, p.b, gcd(p.a, p.b))
printf("u8 %u i64 %" PRId64 "\n", (unsigned int)small, big)
0
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
typedef struct Pair Pair;
struct Pair {
int a,b;
};
unsigned gcd(unsigned a, unsigned b) {
return b ? gcd(b, a % b) : a;
}
int main(void) {
Pair p = {84, 36};
uint8_t small = 200;
int64_t big = INT64_C(1) << 40;
printf("gcd %d %d = %u\n", p.a, p.b, gcd(p.a, p.b));
printf("u8 %u i64 %" PRId64 "\n", (unsigned int)small, big);
return 0;
}
Output
gcd 84 36 = 12
u8 200 i64 1099511627776
What it shows
types, stdint