Mercurial > ~dholland > hg > ag > index.cgi
view help2html/array.h @ 15:f5acaf0c8a29
Don't cast through "volatile int". Causes a gcc warning nowadays.
XXX: should put something else back here to frighten the optimizer
author | David A. Holland |
---|---|
date | Tue, 31 May 2022 01:00:55 -0400 |
parents | 60b08b68c750 |
children |
line wrap: on
line source
#include <assert.h> /* treat as opaque */ struct array { void **v; unsigned num, max; }; struct array *array_create(void); void array_init(struct array *a); void array_cleanup(struct array *a); void array_destroy(struct array *a); static inline unsigned array_num(const struct array *a); static inline void *array_get(const struct array *a, unsigned ix); static inline void array_set(struct array *a, unsigned ix, void *ptr); unsigned array_add(struct array *a, void *ptr); void array_setsize(struct array *a, unsigned newsize); /* compact, removing any null elements */ void array_nonulls(struct array *a); /* x and y are pointers that were placed in the array */ void array_sort(struct array *a, int (*f)(void *x, void *y)); static inline unsigned array_num(const struct array *a) { return a->num; } static inline void *array_get(const struct array *a, unsigned ix) { assert(ix < a->num); return a->v[ix]; } static inline void array_set(struct array *a, unsigned ix, void *ptr) { assert(ix < a->num); a->v[ix] = ptr; }