Void main(void) - the Wrong Thing
users.aber.ac.uk
users.aber.ac.uk
My senior year, they decided to pilot a C programming class. None of the teachers knew C, but one Math teacher volunteered to take night classes and teach us what he was learning.
I would say in about two months, every student in the class was significantly more knowledgeable than the teacher; but he was very cool about it.
The only bad part was he spent about four months on graphics programming; which wouldn't have been bad, except we learned Borland C Graphics (getpixel, putpixel, etc.) which were pretty much useless.
The year culminated in us sending a team to a C Programming Contest being held at a nearby university. I always thought it was amusing that the grand prize (which we didn't win) was a copy of Visual Cafe (the Java IDE).
Anecdote: When corrected, a guy who allegedly coded in C for 10 years even asked what was the use for main to return something :-(( So we talked about unix return values, $? in bash and he had a spark in his eye. I had a tear in mine.
int main(void)--for the lazy AND correct!
Only true for C++.
but it works for me! main(void)
Though I vaguely recall something about this being deprecated in C99.With GCC, you can even set `void main(void) __attribute__((noreturn));` .
(For the lack of a better source, http://www.nongnu.org/avr-libc/user-manual/porting.html )
int f();
and int f(void);
are identical.In C, however,
int f();
Declares a function taking any number of arguments. In C++, that would be denoted as int f(...);
Which is unfortunately a syntax error in traditional C as the ellipsis is only allowed following some explicit parameters. (It's not that big a deal; you'd have to #ifdef __cplusplus
extern "C"
#endif
in the header of the C library for C++ compatibility anyway (to prevent function name mangling and thus link errors), so you can #ifdef the () and (...) too.)FWIW, C++ does support the legacy
int f(void);
syntax, but its use is discouraged except for headers which are also to be used for C code.