#### Archived

This topic is now archived and is closed to further replies.

# Parentheses around return values

## Recommended Posts

Tanuj    128
Chris Hargrove in part 9 of his ''Corn On The Cob'' series says thet he puts parentheses around all the return values,to prevent compiler optimization bugs. Is this really necessary?I am using MS VC++6.0 and am interested in knowing whether the parantheses make any difference.

##### Share on other sites
Rolf    122
Hi man;

Parantehes here and there .....

You generally not use optimise when u debug programs it slows down the compilling.

In VC++ havent heard about such problems in this compilator, but nothing is bug free.

##### Share on other sites
mossmoss    326
quote:
Original post by Tanuj
Chris Hargrove in part 9 of his ''Corn On The Cob'' series says thet he puts parentheses around all the return values,to prevent compiler optimization bugs.

There is no difference between these two return statements:

  return (expr); return expr;

HOWEVER , it is conceivable that a compiler could mess that up, so it''s certainly possible that could be the case. But if that''s so, it''s a messed-up compiler and should be smacked into submission.

---- --- -- -

##### Share on other sites
Guest Anonymous Poster
You will be shocked at the number of bugs in VC. There are quite a few. Most of the common ones are fixed by the service packs.

I am not slagging it off though, I use it myself. I think most of the newer compiler have loads of bugs.

Leave of those (). There is no bug in that area (that microsoft no of, that it).

OpenGL > DirectX

##### Share on other sites
Eck    7581
Greetings,

Mossmoss, says there is no difference between
  return exp;//andreturn (exp);//What if the exp was count++? Isreturn count++;//the same asreturn (count++);

I have not run the test yet and since I am a lazy guy I will let one of you do it. LEt me know how it turns out.

Later,
Eck

Edited by - Eck on July 21, 2000 10:02:30 AM

##### Share on other sites
mossmoss    326
Yeah, I use MSVC regularly and know it has plenty of bugs, including standard C/C++ messups. I don''t know, in particular, if parens missing from the return statement is one of them.

Now, as to the example provided, similar to this:

  //example 1int foo(){ int count = 3; return count++;} //example 2int foo(){ int count = 3; return (count++);}

The return value is exactly the same in both cases -- 3. The value of the expression count++ is 3. The value of (expr) -- whatever expr might be -- is expr.

---- --- -- -