I am new to C and am trying to make an array of one million random __uint128_t
s. Here is my failed attempt:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
void print128(__uint128_t u) {
if (u>9) print128(u/10);
putchar(48+(int)(u%10));
}
typedef __uint128_t u128;
uint64_t wyhash64_x;
uint64_t wyhash64() {
wyhash64_x += 0x60bee2bee120fc15;
__uint128_t tmp;
tmp = (__uint128_t) wyhash64_x * 0xa3b195354a39b70d;
uint64_t m1 = (tmp >> 64) ^ tmp;
tmp = (__uint128_t)m1 * 0x1b03738712fad5c9;
uint64_t m2 = (tmp >> 64) ^ tmp;
return m2;
}
int main() {
u128 vals128[1000000];
u128 lower;
u128 higher;
for (int i = 0; i < 1000000; i++) {
lower = (u128) wyhash64();
higher = (u128) wyhash64();
higher = higher << 64;
vals128[i] = lower + higher;
}
print128(vals128[0]);
printf("\n");
}
This compiles with no warnings but segfaults when I run it.
What am I doing wrong?