c_mem_safety/array_handle_gen_test.c

28 lines
585 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "array.h"
/* Prepare usage for 64 bit arrays - adds "Array_uint64" for creat */
Array(uint64_t, Array_uint64);
int main() {
size_t n = 0;
printf("Number of elements to sum: ");
scanf(" %zu", &n);
2025-04-25 21:44:24 +02:00
/* Create a 64 bit array of 'n' elements named 'data' */
creat(Array_uint64, data, &n);
for(int i = 0; i < data.count; ++i) {
scanf(" %zu", &n);
data.v[i] = n;
}
n = 0; for(int i = 0; i < data.count; ++i) n += data.v[i];
printf("Sum: %zu\n", n);
// RAII releases array here automagicaly!
2025-04-25 21:44:24 +02:00
return 0;
}