Tech Support > Microsoft Windows > Development Resources > "return(0)" vs "return 0" (patience for the un-informed)
"return(0)" vs "return 0" (patience for the un-informed)
Posted by cnlai on January 29th, 2005


What is the difference: "return(0)" vs "return 0" ?

I come across above "return" statements pretty frequently in sample
codes. Is there any difference ?

I don't think "return" is a function call, is it?

Thanks.

Posted by Raymond Martineau on January 29th, 2005


On Sat, 29 Jan 2005 11:14:40 +0800, cnlai <cnlai@pc.jaring.my> wrote:

Using "return (0)" or "return 0"is merely a matter of style. I prefer not
to use parenthesis since it makes the source code smaller, and doesn't
cause unnecessairy work for the compiler.

"return" is a keyword to indicate that the function call should exit.
However, unlike some other flow-control keywords, it does not need any
parenthesis.



Posted by Richard Harris on January 29th, 2005


They both have the same result, but return ( 0 ) is return of an expression,
thus the brakets, return 0 returns a interger value.


"cnlai" <cnlai@pc.jaring.my> wrote in message
news:41FAFFA0.1060507@pc.jaring.my...


Posted by SteveR on January 29th, 2005


cnlai <cnlai@pc.jaring.my> writes:
The difference is that return(0) has redundant () on it, and return 0
does not. There is no other difference. The () are not needed.

--
SteveR
(throw away the dustbin, send to stever@... instead)

Humans are way too stupid to be dumb animals.
http://www.accidentalcreditor.org.uk/

Posted by Iguana on January 31st, 2005


I heard it was bad coding practice (more than one source that I can't
remember at the moment :$) because it makes return look like its a function
(has a return value I assumed) and so decreases readability (decrease as
opposed to make it unreadable).



Posted by Charlie Gibbs on January 31st, 2005


In article <ctlah7$9ra$1@news.freedom2surf.net>, hairnet@f2s.com
(Iguana) writes:

None.

That's a matter of opinion. I always opt for the parentheses.
To me it actually increases readability since it makes the
return value stand out. And if the value is an expression,
it ensures that everything is kept neat and tidy.

But being the belt-and-suspenders sort of guy that I am, I tend
to use parentheses where they aren't strictly necessary, e.g.

if ((foo == 1) && (*bar != NULL)) {
if (*bar == 2) {
...

I know that according to C's rules of operator precedence and
expression evaluation, I could simply say

if (foo == 1 && *bar != NULL && *bar == 2) {
...

but I think my way makes it more obvious. Plus, if I ever
re-write the expression in another language with different
rules, it'll still work.

As usual, your mileage may vary.

--
/~\ cgibbs@kltpzyxm.invalid (Charlie Gibbs)
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!


Posted by Fenster on February 1st, 2005


In message <1439.892T2075T5925524@kltpzyxm.invalid>, Charlie Gibbs
<cgibbs@kltpzyxm.invalid> writes
I'm with you Charlie, on every point (other than I would test "1 == foo"
rather than "foo == 1" but that's another story).

I'd also like to add that, in my case at least, it probably has a lot to
do with my original C tutor; that's the way he did it so that's the way
he taught me so that's how I do it, being the diligent, obedient little
sod that I am.

--
Fenster