I am looking at a piece of code from an exercise in the C Programming Language. It uses the clock_t data type for one of its variables. And then later when it prints the data of the variable, it does a cast to an unsigned long:
Code:
int main(void) {
int testdata[MAX_ELEMENT];
int index; /* Index of found element in test data */
int n = -1; /* Element to search for */
int i;
clock_t time_taken;
for ( i = 0; i < MAX_ELEMENT; ++i )
testdata[i] = i;
for ( i = 0, time_taken = clock(); i < 100000; ++i ) {
index = binsearch(n, testdata, MAX_ELEMENT);
}
time_taken = clock() - time_taken;
printf("binsearch() took %lu clocks (%lu seconds)\n",
(unsigned long) time_taken,
(unsigned long) time_taken / CLOCKS_PER_SEC);
Is there any particular reason to cast to unsigned long here rather than just using clock_t since that is what it was initialized to?