Hacker News new | past | comments | ask | show | jobs | submit login

Quick question: why does he do this?

    int main(int argc, char * argv[]) {
      (void)argc;
      (void)argv;
I've programmed C while in school, but I don't remember ever seeing this and I'm not sure how to google it.



It stops the compiler from complaining about unused variables:

http://stackoverflow.com/questions/8052091/void-cast-of-argc...


Why would you do this instead of declaring it as `int main(void)`?


I use clang with a -Wall and -Wextra, which will complain about all sorts of stuff I generally want to know about, including unused variables (I think gcc does the same?). For the rare cases where I actually want to leave a variable unused I do the above to make the warning go away.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: