Archived

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

Tanuj

Parentheses around return values

Recommended Posts

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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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.


---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!

Share this post


Link to post
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 this post


Link to post
Share on other sites
Greetings,

Mossmoss, says there is no difference between
        
return exp;
//and

return (exp);

//What if the exp was count++? Is

return count++;
//the same as

return (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 this post


Link to post
Share on other sites
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 1

int foo()
{
int count = 3;
return count++;
}

//example 2

int 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.


---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!

Share this post


Link to post
Share on other sites