That looked like one huge macro, but it turns out that the code in your post had some formatting issues so it is actually:
Code:
#define ZeroStruct(Instance) ZeroSize(sizeof(Instance), &(Instance))
#define ZeroArray(Count, Pointer) ZeroSize(Count * sizeof((Pointer)[0]), Pointer)
inline void ZeroSize(memory_index Size, void *Ptr)
{
uint8 *Byte = (uint8 *)Ptr;
while (Size--)
{
*Byte++ = 0;
}
}
It is easy to understand why ZeroStruct is a function-style macro: it is supposed to work with arguments of different types, and hence if you don't want to repeat writing the same function for each struct type, you would need to have a void* parameter for the function, in which case you would have to pass the size too, upon which you might as well call ZeroSize directly. Hence, a function-style macro allows the "caller" to pass the struct object directly, regardless of its type.
ZeroArray has a similiar idea: here, Pointer can point to the first element of arrays of varying element types. If you wish to write it as a function, it would be something like:
Code:
void ZeroArray(size_t Count, void *Pointer, size_t ElementSize)
{
ZeroSize(Count * ElementSize, Pointer);
}
and you would call it like this:
Code:
ZeroArray(100, SomeArray, sizeof(SomeArray[0]));
contrast with the macro, where you don't have to pass the element size because the macro would be replaced with code in the context of the macro invocation, hence the element size can be determined from the sizeof within the macro:
Code:
ZeroArray(100, SomeArray);