In my function, I first use mod as below:
void function(int, int, unsigned int);
calling:
function(100, 200, get_value() % 1024);
The get_value() will return a unsigned int that varies from 0x0 to 0xffffffff. In this situation get_value() % 1024 may be a very big number larger than 1024 that causes function() to run too many times, so I changed it as below:
unsigned int num = get_value() % 1024;
function(100, 200, num);
In this situation, num is ok. I used gcc to compile.
So what is the difference between these two methods and how does C calcuate modulus for unsigned long?
Your prototype is for
function, but you are callingfunction1. In this case, thefunction1function has no prototype, so the last parameter is considered to be anint. That’s why you do not get the expected conversion.Renaming the prototype should fix it: