func(void) or func() ?
-
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); I think this is more in keeping with the C++ standard. In C a function declared with no arguments can take any number of arguments of any type. This is not the same in C++ (According to Stroustrup B2.2). 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.
Robert Edward Caldecott wrote: void SomeFunc(); This is old K&R C style. It's supported for backward compatibility. Robert Edward Caldecott wrote: void SomeFunc(void); This is C++ style. Do you know the programming forums? They are nice ;P lazy isn't my middle name.. its my first.. people just keep calling me Mel cause that's what they put on my drivers license. - Mel Feik
-
Robert Edward Caldecott wrote: ...are there any benefits to void? No, just going it right. I think it is in the same line with the following
main()
}
}our own main! in C is void main() {}. However in C++, it is int main() {} ;P Robert Edward Caldecott wrote: What do you prefer for your member functions Whenever, I have enjoyed a good meal I prefer void SomeFunc(void); otherwise void SomeFunc(); ;P Best regards, Paul. Jesus Christ is LOVE! Please tell somebody.
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
-
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
I think the point here is leaving out the void. It has nothing to do with declaring main as either void or int. Best regards, Paul. Jesus Christ is LOVE! Please tell somebody.
-
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++. Wrong. void main is an aberation tolerated by bad compilers such as VC++. Post an example with void main into comp.lang.c++, and watch how many people jump to tell you that is not C++, as defined by the standard, at all. 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
-
Robert Edward Caldecott wrote: void SomeFunc(); This is old K&R C style. It's supported for backward compatibility. Robert Edward Caldecott wrote: void SomeFunc(void); This is C++ style. Do you know the programming forums? They are nice ;P lazy isn't my middle name.. its my first.. people just keep calling me Mel cause that's what they put on my drivers license. - Mel Feik
Daniel Turini wrote: Robert Edward Caldecott wrote: void SomeFunc(void); This is C++ style. It's not C++ at ALL, nor can I find an example in Stroustrup where he declares void as the parameters. I always thought that declaring void was C, I've never seen it in a C++ program. 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
-
Daniel Turini wrote: Robert Edward Caldecott wrote: void SomeFunc(void); This is C++ style. It's not C++ at ALL, nor can I find an example in Stroustrup where he declares void as the parameters. I always thought that declaring void was C, I've never seen it in a C++ program. 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
-
Daniel Turini wrote: Robert Edward Caldecott wrote: void SomeFunc(void); This is C++ style. It's not C++ at ALL, nor can I find an example in Stroustrup where he declares void as the parameters. I always thought that declaring void was C, I've never seen it in a C++ program. 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
-
Christian Graus wrote: I always thought that declaring void was C, I've never seen it in a C++ program. You haven't looked at any of my source then. ;) Anna :rose: "Be yourself - not what others think you should be"
- Marcia GraeschAnna :) 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
-
Vagif Abilov wrote: main function can be declared as returning void or int both in C and C++. Wrong. void main is an aberation tolerated by bad compilers such as VC++. Post an example with void main into comp.lang.c++, and watch how many people jump to tell you that is not C++, as defined by the standard, at all. 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
Post almost *anything* into comp.lang.c++ and see how many people jump on your post. I have to say it's the most unhelpful group on usenet. The people there seem to take much more interest in putting people down than it trying to help them.
-
Post almost *anything* into comp.lang.c++ and see how many people jump on your post. I have to say it's the most unhelpful group on usenet. The people there seem to take much more interest in putting people down than it trying to help them.
-
Post almost *anything* into comp.lang.c++ and see how many people jump on your post. I have to say it's the most unhelpful group on usenet. The people there seem to take much more interest in putting people down than it trying to help them.
That is probably true, but I suspect it's partly because they are sick of being asked Windows programming questions. Either way, void main is plain wrong, that is all I was trying to say. And while it can be daunting, comp.lang.c++ is a hell of a good place to improve your C++ skills. 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
-
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
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
-
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.