From 27b42b6ed1105a7f9af750f48b5b4fa985bfac12 Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Fri, 17 Nov 2023 12:51:26 -0400 Subject: [PATCH] Add some documentation --- foreach.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/foreach.h b/foreach.h index 5e88f6a..0ce542c 100644 --- a/foreach.h +++ b/foreach.h @@ -1,9 +1,11 @@ -#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++) +#pragma once + +// Will determine the size of an array only if it is declared on the stack +// Need to dereference the item, as it is a pointer to the current element +#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 +// Need to dereference the item, as it is a pointer to the current element +#define foreach_p(type, item, array, size) \ + for (type* item = array; item < array + size; item++)