returns in parenthesis

Discussion in 'C Programming' started by Bill Cunningham, Dec 29, 2013.

  1. 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
     
    Bill Cunningham, Dec 29, 2013
    #1
    1. Advertising

  2. wrote:
    > "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
     
    Bill Cunningham, Dec 29, 2013
    #2
    1. Advertising

  3. Bill Cunningham

    Siri Cruz Guest

    In article <VbLvu.113147$>,
    "Bill Cunningham" <> wrote:

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

    --
    :-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted.
    'I desire mercy, not sacrifice.'
     
    Siri Cruz, Dec 29, 2013
    #3
  4. Siri Cruz <> writes:

    > In article <VbLvu.113147$>,
    > "Bill Cunningham" <> wrote:
    >
    >> 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.


    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.

    --
    Ben.
     
    Ben Bacarisse, Dec 29, 2013
    #4
  5. Ben Bacarisse wrote:
    > 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
     
    Bill Cunningham, Dec 29, 2013
    #5
  6. "Bill Cunningham" <> writes:
    > 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).

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Working, but not speaking, for JetHead Development, Inc.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 29, 2013
    #6
  7. 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
     
    Bill Cunningham, Dec 29, 2013
    #7
  8. In article <>, Richard <>
    wrote:

    > "Bill Cunningham" <> writes:
    >
    > > 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
    > >

    >
    > Good to see your trolling is going strong Bill!
    >
    > 7/10.


    c.l.c feeding the trolls

    10/10.
     
    Mark Storkamp, Dec 29, 2013
    #8
  9. Bill Cunningham

    osmium Guest

    "Mark Storkamp" wrote:

    > In article <>, Richard <>
    > wrote:
    >
    >> "Bill Cunningham" <> writes:
    >>
    >> > 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
    >> >

    >>
    >> Good to see your trolling is going strong Bill!
    >>
    >> 7/10.

    >
    > c.l.c feeding the trolls
    >
    > 10/10.


    11/10
     
    osmium, Dec 29, 2013
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. .Net Sports
    Replies:
    4
    Views:
    2,156
    Eliyahu Goldin
    Jun 29, 2005
  2. puzzlecracker
    Replies:
    0
    Views:
    461
    puzzlecracker
    Jan 25, 2006
  3. Rogue Noir
    Replies:
    6
    Views:
    2,485
    Arquebus257WeaMag
    Aug 2, 2003
  4. Bob Day
    Replies:
    1
    Views:
    322
    osmium
    Jul 11, 2003
  5. Mr. 4X
    Replies:
    5
    Views:
    320
    Kenny McCormack
    Jul 16, 2003
Loading...

Share This Page