Skip to content

cppf/extra-array

Repository files navigation

Generic array in C.

Download: header file.

structure

at : T*
size : size_t

usage

declare

// Declare array type.
// This defines structure and declares functions.
EARRAY_DECLARE(name, type)
// declare int array
EARRAY_DECLARE(AInt, int)

define

// Define array type.
// This defines functions.
EARRAY_DEFINE(name, type)
// define int space
EARRAY_DEFINE(AInt, int)

open

// Open with static memory.
#_open(array, at, size)
// define array and char buffer
AInt o;
char buffer[32];

// open with buffer
AInt_open(&o, buffer, 32/sizeof(int));

// print size of array
printf("%zu", o.size);

// write 0x0BADB055 at last index
o.at[o.size-1] = 0x0BADB055;

openHeap

// Open with heap memory.
#_openHeap(array, size)
// open of size 64
AInt_openHeap(&o, 64);

// print size of array
printf("%zu", o.size);

// write 0x600DB055 at last index
o.at[o.size-1] = 0x600DB055;

close

// Close, if opened with heap memory.
#_close(array)
// close array
AInt_close(&o);

resize

// Resize if opened with heap memory.
#_resize(array, size)
// open of size 128
AInt_openHeap(&o, 128);

// resize to size 256
AInt_resize(&o, 256);

// print size of array
printf("%zu", o.size);

// close array
AInt_close(&o);



cppf