(void)time(&cur_time); Why did the author put (void) here?
Code:
A program from 《BeginningLinuxProgramming》. |
The void is merely to tell the program that the return value should be ignored. Certain compiler flag(s) may issue a warning if the void is not specified. The author of the code could just have easily done something like:
Code:
time_t cur_time = time(NULL); |
Quote:
But I still don't understand.Why the return value should be ignored here.Without (void),gcc didn't show any warning. Do you mean we should put(void) before a function whose return value is not used. |
Pardon my choice of words earlier... I erred in using the word "should"; I meant to use "can".
One does not need to explicitly ignore the return value; some programmers just like to be over-zealous with their code. I briefly glanced through the man-page for gcc to see if I can locate an option that would produce a warning that the return value is not be used, but I could not find one. Suffice to say, I've been developing code for over 20 years; not once have I ever explicitly placed a void in front of a function that is called. |
All times are GMT -5. The time now is 10:08 PM. |