I'm used to C++ and I just started to use C and I'm not sure if it is neccessary or just recommended to add 'void' in a empty parameter list in a function.
I'm used to C++ and I just started to use C and I'm not sure if it is neccessary or just recommended to add 'void' in a empty parameter list in a function.
When you are defining a function, the void parameter is unnecessary. If you are declaring a function (prototype), the void parameter means that the function takes no arguments. If you leave out the void, then the number of arguments that the function can take is left unspecified.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Is that bad?
Well, if you intend a function to have no parameters, why not declare its prototype stating your intention explicitly?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Alright. Thanks for the reply.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
That's a difference between C and C++ (C++ accepts the void but it doesn't work the other way round - no void still means no arguments).
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
I almost always declare a function with no arguments as func( void ) as well as I always write return( something ). (with brackets)
Call me old fashioned, but imho it's a question of continuity and clearness.
But it is not needed there either...
Another thing, do you use brackets for the case statement too?
Code:switch (n) { case (FIRST_OPTION) ...
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
I use ( ) for the return statement because it resembles a function to me.
I don't use ( ) for case because case looks like a label to me.
Just a personal preference unless someone can explain why it is bad.
As you say, it is personal (or sometimes corporate) preference. On one hand, putting in the parentheses where they are not necessary clutters up the code. On the other hand, leaving them out could result in ambiguity to a reader who is not as familiar with precedence. With that in mind, I leave out the parentheses for return statements where precedence does not come into play.Just a personal preference unless someone can explain why it is bad.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)