I have a function which looks something like this void doSomething(unsigned char buff[50]);
What I would like to do in my function is quickly determine if the buff is all nulls.
To do that I was thinking I could just bitwise or the buffer and check if the result is zero, since any on byte would cause the result of a bitwise or to be to be 1. A result of zero would indicate that all bytes in the array are zero.
Is there an easy way to do this in C without looping over the entire buffer?
It would be nice if it were cross platform.
No. But you can reduce the number of iterations by casting to a 32- or 64-bit type before doing the checking. Just make sure to handle the extra 16 bits at the end properly.