X
x_knifer_x
read the subject it says it all
int main(void) is better than int main()
int main(void) is better than int main()
read the subject it says it all
int main(void) is better than int main()
read the subject it says it all
int main(void) is better than int main()
read the subject it says it all
Lars said:your point being...?
read the subject it says it all
int main(void) is better than int main()
You are not a troll. The quest for knowledge is not troll-ish.
read the subject it says it all
int main(void) is better than int main()
There is no difference.
James said:As far as the compiler is concerned, no. As far as anyone who
reads the code is concerned, the first marks you as a C hacker,
who doesn't understand C++.
Now we're getting to where it becomes interesting
Maybe I don't understand C++ then - after all I did start with Ansi C -
I always thought "int main (void)" was the way to go because - as you
stated later in your post - compilers would complain otherwise. As for
C++, if there is no difference on compiler side, I don't see what the
problem is keeping void in there, even if it is not required. Please
enlighten me...
It slows down reading (and writing),
foo() clearly indicates that there
are no arguments, foo(void) at a glance looks like it takes an argument
and you have to see that the type is void before you understand that
there are no arguments.
Why should we have to tell the compiler that
there are no arguments when an empty list works just as well, and is
more consistent.
On the other hand, I find it very nice that
foo( void )
does not look like the function call and clearly indicates that I am looking
at a declaration. For that reason, it also increases grep-ability of the
code.
Lars said:Now we're getting to where it becomes interesting
Maybe I don't understand C++ then - after all I did start with
Ansi C - I always thought "int main (void)" was the way to go
because - as you stated later in your post - compilers would
complain otherwise.
As for C++, if there is no difference on compiler side, I
don't see what the problem is keeping void in there, even if
it is not required. Please enlighten me...
Obviously, I don't understand C++, too. I, however, came from
Pascal and Modula 2. I have never programmed in C.
I cannot not confirm that. But then again, I am used to much
more verbose languages.
I don't think the psychology of reading code (as opposed to
the logic of parsing) works that way.
On the other hand, I find it very nice that
foo( void )
does not look like the function call and clearly indicates
that I am looking at a declaration. For that reason, it also
increases grep-ability of the code.
It doesn't belong in C++, but it does in C where K&R style functionLars said:Now we're getting to where it becomes interesting
Maybe I don't understand C++ then - after all I did start with Ansi C -
I always thought "int main (void)" was the way to go because - as you
stated later in your post - compilers would complain otherwise. As for
C++, if there is no difference on compiler side, I don't see what the
problem is keeping void in there, even if it is not required. Please
enlighten me...
Ian said:It doesn't belong in C++, but it does in C where K&R style function
declarations are still legal. In C, f() and f(void) have different
meanings, where they do not in C++.
The C standardLars said:After reading James' comments - especially on the grepability - that
function declarations should (and in my case do) start in the first
column, I've decided to use "int main() {}" in the future.
But could you explain the different meanings of f() and f(void) in C to
me? Or rather - point me to a source where it is explained?
Ian said:void f(); /* Declares a function with unknown parameters */
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.