foreach-c/foreach.h

10 lines
404 B
C
Raw Normal View History

2023-11-17 12:40:31 -04:00
#pragma once
// Will determine the size of an array only if it is declared on the stack
#define foreach(type, item, array) \
for (type* item = array; item < array + (sizeof(array) / sizeof(type)); item++)
// Need to pass in the size of the array, since heap allocated arrays don't work with sizeof
#define foreach_p(type, item, array, size) \
for (type* item = array; item < array + size; item++)