returns in parenthesis

B

Bill Cunningham

What is the difference in return statements in parenthesis and not. I've
never used return(); I've never had a problem with a return statement. My
compiler is C99 too and there is *no* C11 to it. Are they slow on these?

Bill
 
B

Bill Cunningham

"return" statements in parentheses are illegal. Examples:

(return);
(return ;)
(return 0);
(return 0;)

are all illegal.

I'm sorry. I misspoke. It's return and then a statement in () and it
also doesn't have to be in (). I've never used () and just wordered what it
meant. i.e.

return (TRUE);

When I said /are they slow on these/ I was speaking of being slow to get the
C11 compatible compilers out.

Bill
 
S

Siri Cruz

Bill Cunningham said:
What is the difference in return statements in parenthesis and not. I've
never used return(); I've never had a problem with a return statement. My
compiler is C99 too and there is *no* C11 to it. Are they slow on these?

Similar looking statements like if(), while(), for() do have mandatory
parenthesis, so sometimes we just unconsciously add them to return on analogy.
It doesn't help anything, but it doesn't hurt either.
 
B

Ben Bacarisse

Siri Cruz said:
Similar looking statements like if(), while(), for() do have mandatory
parenthesis, so sometimes we just unconsciously add them to return on
analogy.

And Very Old C insisted on them -- a syntax inherited from B. They were
optional before K&R was first published, but it took me a while to stop
using them as I'd learned B before C.
 
B

Bill Cunningham

Ben said:
And Very Old C insisted on them -- a syntax inherited from B. They
were optional before K&R was first published, but it took me a while
to stop using them as I'd learned B before C.

You've been around this for a very long time. No wonder you are such an
expert.

Bill
 
K

Keith Thompson

Bill Cunningham said:
What is the difference in return statements in parenthesis and not. I've
never used return(); I've never had a problem with a return statement. My
compiler is C99 too and there is *no* C11 to it. Are they slow on these?

The syntax of a return statement is:

return expression(opt) ;

For a return statement returning a value, parentheses around
expression harmless but are never necessary. (In my humble opinion
adding optional parentheses is poor style because they make the
return statement look like a function call, which it isn't.)

Parentheses are allowed because an expression in parentheses is a valid
expression, exactly equivalent in type, value, and other characteristics
to the unparenthesized expression. There is no reason for performance
to vary depending on the presence or absence of parentheses.

For a return statement that doesn't return a value (used in a void
function):

return;

parentheses are illegal:

return(); /* syntax error */

This has nothing to do with C99 or C11. In the 1975 version of the C
Reference manual, parentheses were required for a return statement with
an expression. I *think* that they were dropped in the 1978 first
edition of K&R (I'll have to check later).
 
B

Bill Cunningham

Keith Thompson wrote:
[snip]
For a return statement returning a value, parentheses around
expression harmless but are never necessary.
[snip]

I thought C was always return a value. Or is that *pass* by value. If
there's a difference.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top