For a homework assignment, we've been asked to write a preprocessor macro that sums the elements of an array.
My question is, how can I process array elements within a macro in such a way that could expand to a sum (or any other mathematical operation on the elements)?
There's nothing in our book that mentions processing array elements or even accessing them, and I can't find many helpful resources online as a macro wouldn't be the typical way to deal with something like this. I know there are way better ways to do such a thing, but I understand that the idea is to get us better familiar with preprocessor macros.
When I go about writing the macro in the style of a function, I don't know how to "return" the sum to the program. The only way I can think of to get the macro to expand to a sum is if it were done recursively, and I'm not even sure if you can recurse with macros. I've written a macro that successfully expands to the size of the array, but I'm not sure which direction to go from there.