libFirm
array.h File Reference

Dynamic and flexible arrays for C. More...

#include <assert.h>
#include <stddef.h>
#include "obst.h"
#include "../begin.h"
#include "../end.h"

Go to the source code of this file.

Macros

#define NEW_ARR_F(type, nelts)   ((type *)ir_new_arr_f((nelts), sizeof(type) * (nelts)))
 Creates a flexible array.
#define CLONE_ARR_F(type, arr)   NEW_ARR_F(type, ARR_LEN((arr)))
 Creates a new flexible array with the same number of elements as a given one.
#define DUP_ARR_F(type, arr)   ((type*) memcpy(CLONE_ARR_F(type, (arr)), (arr), sizeof(type) * ARR_LEN((arr))))
 Duplicates an array and returns the new flexible one.
#define DEL_ARR_F(arr)   (ir_del_arr_f((void *)(arr)))
 Delete a flexible array.
#define NEW_ARR_D(type, obstack, nelts)
 Creates a dynamic array on an obstack.
#define CLONE_ARR_D(type, obstack, arr)   NEW_ARR_D(type, (obstack), ARR_LEN((arr)))
 Creates a new dynamic array with the same number of elements as a given one.
#define DUP_ARR_D(type, obstack, arr)   ((type*)memcpy(CLONE_ARR_D(type, (obstack), (arr)), (arr), sizeof(type) * ARR_LEN ((arr))))
 Duplicates an array and returns the new dynamic one.
#define ARR_LEN(arr)   (ARR_VRFY((arr)), ARR_DESCR((arr))->nelts)
 Returns the length of an array.
#define ARR_RESIZE(type, arr, n)   ((arr) = (type*) ir_arr_resize((void *)(arr), (n), sizeof(type)))
 Resize a flexible array, allocate more data if needed but do NOT reduce.
#define ARR_SETLEN(type, arr, n)   ((arr) = (type*) ir_arr_setlen((void *)(arr), (n), sizeof(type) * (n)))
 Resize a flexible array, always reallocate data.
#define ARR_EXTEND(type, arr, delta)   ARR_RESIZE(type, (arr), ARR_LEN((arr)) + (delta))
 Resize a flexible array by growing it by delta elements.
#define ARR_EXTO(type, arr, n)
 Resize a flexible array to hold n elements only if it is currently shorter than n.
#define ARR_APP1(type, arr, elt)   (ARR_EXTEND(type, (arr), 1), (arr)[ARR_LEN((arr))-1] = (elt))
 Append one element to a flexible array.
#define ARR_VRFY(arr)   ir_verify_arr(arr)
 Check array for consistency.
#define ARR_IDX_VRFY(arr, idx)   assert((0 <= (idx)) && ((idx) < ARR_LEN((arr))))
 Check if index is within array bounds.

Detailed Description

Dynamic and flexible arrays for C.

Author
Markus Armbruster, Michael Beck, Matthias Braun, Sebastian Hack

Definition in file array.h.