Re: int main(void) is better than int main()



 DEVELOP > c-Plus-Plus > Re: int main(void) is better than int main()

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Tristan Wibberley"
Date: 04 Jan 2008 09:20:51 AM
Object: Re: int main(void) is better than int main()
On Thu, 2008-01-03 at 15:38 +0100, Lars Uffmann wrote:

Erik Wikstr=C3=B6m wrote:

foo() clearly indicates that there =20
are no arguments, foo(void) at a glance looks like it takes an argumen=

t

and you have to see that the type is void before you understand that
there are no arguments.

=20
@Erik: point taken, at this point I was ready to accept this and apply=20
it to my own code, but then...
=20
jkherciueh@gmx.net wrote:

On the other hand, I find it very nice that=20
foo( void )
does not look like the function call and clearly indicates that I am lo=

oking

at a declaration. For that reason, it also increases grep-ability of th=

e

code.

=20
=20
Kai-Uwe also has a very good point there. Especially on the grep-ability =

:)

=20
I'm thinking especially about forward declarations that will look=20
exactly like a function call. Have to chew on this for a bit - unless=20
someone comes up with better arguments ;) Thanks to both of you!

I suppose something like this would be nasty:
#define UI_DEFAULT_MYOBJ_ARGS 0, "foo"
struct myclass {
myclass(int, const std::string&);
myclass();
};
void ui_default_path()
{
myclass myobj(UI_DEFAULT_MYOBJ_ARGS);
// .. do stuff ..
}
and then somebody redefines =EF=BB=BFUI_DEFAULT_MYOBJ_ARGS
#define =EF=BB=BFUI_DEFAULT_MYOBJ_ARGS
confusing compile error ensues.
The next version of C++ will probably have curly braces for
initialisation which can be used to prevent this problem occuring.
--=20
Tristan Wibberley
Any opinion expressed is mine (or else I'm playing devils advocate for
the sake of a good argument). My employer had nothing to do with this
communication.
.

User: "Lars Uffmann"

Title: Re: int main(void) is better than int main() 07 Jan 2008 02:16:34 AM
Tristan Wibberley wrote:

I suppose something like this would be nasty:

#define UI_DEFAULT_MYOBJ_ARGS 0, "foo"
[..]

I suppose that is probably 2 levels above my current programming skills *G*
Sorry - didn't understand much of that, if anything.
Thanks anyways :)
Lars
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER