Re: (part 21) Han from China answers your C questions
On Sat, 15 Nov 2008 11:04:03 -0800, Keith Thompson wrote:
I'd like to stay out of the main discussion, but I'm curious how you feel
about this?
int main(void);
int main() {
/* ... */
}
Is this equivalent to
int main(void) {
/* ... */
}
? If not, in what way are these not equivalent?
Perhaps also interesting is that
int main(int argc, char *argv[]) {
/* ... */
}
is not equivalent to
int main(int argc, char *argv[]);
int main(argc, argv)
int argc;
char *argv[];
{
/* ... */
}
because the latter allows main to be called as
int (*mainptr)() = &main;
(*mainptr)(1u, (char **) 0);
while the former doesn't, but this doesn't apply to () versus (void).
On Sat, 15 Nov 2008 11:04:03 -0800, Keith Thompson wrote:
Yes, either "int main(void) { ... }" or "int main() { ... }" defines
main as taking no parameters; they're similar in that way. But one
similarity doesn't make them equivalent.
main as taking no parameters; they're similar in that way. But one
similarity doesn't make them equivalent.
about this?
int main(void);
int main() {
/* ... */
}
Is this equivalent to
int main(void) {
/* ... */
}
? If not, in what way are these not equivalent?
Perhaps also interesting is that
int main(int argc, char *argv[]) {
/* ... */
}
is not equivalent to
int main(int argc, char *argv[]);
int main(argc, argv)
int argc;
char *argv[];
{
/* ... */
}
because the latter allows main to be called as
int (*mainptr)() = &main;
(*mainptr)(1u, (char **) 0);
while the former doesn't, but this doesn't apply to () versus (void).
Comment