OK I'm pretty much a C programming newbie (or to be more accurate and 'oldbie' who has forgotten nearly all he ever knew) and I'm trying to get the handle on some subtle differences between two sets of code that do the same (or similar) thing.
This is a macro from Program A
And this is an example of it in useCode:/* Wipe an array of type T[N], at location P, and return P */ #define C_WIPE(P, N, T) \ (memset((P), 0, (N) * sizeof(T)))
Now the same area from the (distant relation) Program BCode:/* Clear the "aux" array */ (void)C_WIPE(aux, MAX_DEPTH, s16b);
and it in useCode:/* Wipe an array of type T[N], at location P, and return P */ #define C_WIPE(P,N,T) \ (T*)(memset((char*)(P),0,(N) * sizeof(T)))
The code in Program B was probably previously used in Program A before being updated, so I might assume that A is more 'correct', but it is not clear to me why (if so).Code:/* Clear the "aux" array */ C_WIPE(&aux, MAX_DEPTH, s16b);
Some things that I did think
& (address of) and * (pointer to)
look like they'd cancel each other out so I'm not sure why version B goes round the houses like it seems to do. Unless it's to turn it into a pointer to char type in particular.
B takes the trouble to return it as 'pointer to type T' but in practice the return value is not looked at in any code used in the program (sometimes it is cast to (void), sometimes not).