func(void) or func() ?
-
Anna :) wrote: You haven't looked at any of my source then. Fair enough... I knew it could be done that way, you understand, it's just that with all the people I have worked with, all the code I have downloaded and all the books I have read ( including both from Stroustrup ), I've never seen it used. I don't think it's particularly wrong, only void main is actually *wrong*, but I see a fair bit of it, and as I say, no int main(void) Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
Having never read a C++ book until after I learnt the language :eek: it just made sense to me that if you have to specify that a method returns void, it was more consistant to specify it for methods which take no parameters also. :) As it's not mandated either way by the language spec, it really comes down to personal style. It is notable though that if you try to declare a C# method with parameter "void" the compiler barfs at you..which only goes to reinforce one of your earlier sigs. ;) Anna :rose: "Be yourself - not what others think you should be"
- Marcia Graesch -
Since upgrading to VS.NET I have noticed that any classes I add using the "Add New Class" wizard will use
void
for functions with no params (such as constructors/destructors). Personally, I haven't bothered doing this sonce my C days, so my question is - are there any benefits tovoid
? What do you prefer for your member functions:void SomeFunc(void);
orvoid SomeFunc();
When I am king, you will be first against the wall.
in C#,
void SomeFunc(void)
is not a legal syntax. A parameterless function must be declaredvoid SomeFunc()
. It drives me crazy, especially because I like the first way to explicitly say "this function takes no parameters". Oh well. Marc Help! I'm an AI running around in someone's f*cked up universe simulator. -
in C#,
void SomeFunc(void)
is not a legal syntax. A parameterless function must be declaredvoid SomeFunc()
. It drives me crazy, especially because I like the first way to explicitly say "this function takes no parameters". Oh well. Marc Help! I'm an AI running around in someone's f*cked up universe simulator. -
Stroustrup had an article in CUJ a couple of months ago on the subject "C and C++ compatibility", he mentions the empty parameter list vs. the void parameter list and one of them is supposed to mean that the function may take a parameter of any type, but I can't remember which... "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
jan larsen wrote: one of them is supposed to mean that the function may take a parameter of any type, but I can't remember which... See my post above. Dave.
-
Since upgrading to VS.NET I have noticed that any classes I add using the "Add New Class" wizard will use
void
for functions with no params (such as constructors/destructors). Personally, I haven't bothered doing this sonce my C days, so my question is - are there any benefits tovoid
? What do you prefer for your member functions:void SomeFunc(void);
orvoid SomeFunc();
When I am king, you will be first against the wall.
-
From the C++ standard: If the parameterdeclarationclause is empty, the function takes no arguments. The parameter list (void) is equivalent to the empty parameter list. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
main function can be declared as returning void or int both in C and C++. If you declare it as int, you let your program return a value (typically an error code) that operating system or calling process can use. Vagif Abilov MCP (Visual C++) Oslo, Norway Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros. Tomasz Sowinski
Vagif Abilov wrote: main function can be declared as returning void or int both in C and C++ Returning void is not standard C++. The standard C++ version of main is
int main()
{
}
There are only 10 kind of people in the world: those who understand binary and those who don't.
-
Since upgrading to VS.NET I have noticed that any classes I add using the "Add New Class" wizard will use
void
for functions with no params (such as constructors/destructors). Personally, I haven't bothered doing this sonce my C days, so my question is - are there any benefits tovoid
? What do you prefer for your member functions:void SomeFunc(void);
orvoid SomeFunc();
When I am king, you will be first against the wall.
I don't care, I decided to use only the following prototype for all of my C functions, and use casting till death!
void someFunc( const void * const * const args )
{}
and deal with it later ! Max.
-
Since upgrading to VS.NET I have noticed that any classes I add using the "Add New Class" wizard will use
void
for functions with no params (such as constructors/destructors). Personally, I haven't bothered doing this sonce my C days, so my question is - are there any benefits tovoid
? What do you prefer for your member functions:void SomeFunc(void);
orvoid SomeFunc();
When I am king, you will be first against the wall.
Robert Edward Caldecott wrote: void SomeFunc(void); This isn't C++ style it's C style
There are only 10 kind of people in the world: those who understand binary and those who don't.
-
I don't care, I decided to use only the following prototype for all of my C functions, and use casting till death!
void someFunc( const void * const * const args )
{}
and deal with it later ! Max.
:-) Well good for you! But shouldn't you be returning
void*
? Regards, Alvaro
Well done is better than well said. -- Benjamin Franklin
-
Stroustrup had an article in CUJ a couple of months ago on the subject "C and C++ compatibility", he mentions the empty parameter list vs. the void parameter list and one of them is supposed to mean that the function may take a parameter of any type, but I can't remember which... "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
I have that issue, I may pull it out. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002