Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> in C this function takes any number of arguments ... I guess it’s a leftover ‘syntax pollution’ from old K&R style function declaration syntax). ... Instead in C, declare the parameter list explicitely as ‘void’ so that you actually get compiler errors when accidently passing arguments to ‘my_func()’ ...

I thought that C99 got rid of the "implicitly allows any number of arguments" thing. Maybe I'm mistaken.

The place where I used to see this was header files that might be used by a pre-ANSI compiler. They would omit arguments in the header declarations of functions. I even remember some X11 headers putting those arguments in an ifdef, so that if you had a decent compiler you'd get the checks, but it would still work on ancient compilers.

It wasn't that the function bodies would have args missing and somehow use them. It was about declarations, the kind you see in header files.



C23 finally gets rid of it, along with a couple of other warts (like '= {0};' to zero-initialize a struct, instead '= {};' is allowed now).




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

Search: