Empty parentheses

Discussion in 'C Programming' started by Christopher Benson-Manica, Oct 17, 2003.

  1. I understand the rationale behind declaring function definitions such as

    int main() { return 0; } /* empty parentheses */

    obsolete, but I haven't been able to find out why Dennis Ritchie despised them
    enough to call them an "abomination." Comments and/or links appreciated.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Oct 17, 2003
    #1
    1. Advertising

  2. Christopher Benson-Manica

    xarax Guest

    "Christopher Benson-Manica" <> wrote in message
    news:bmosk3$phg$...
    > I understand the rationale behind declaring function definitions such as
    >
    > int main() { return 0; } /* empty parentheses */
    >
    > obsolete, but I haven't been able to find out why Dennis Ritchie despised them
    > enough to call them an "abomination." Comments and/or links appreciated.


    IIRC, the empty parens is the same as:

    int main(...);

    which means variable number of arguments. VARARGS
    are pita, and have implementation-dependent issues.

    If you really want an empty parameter list,
    then the proper declaration is:

    int main(void);

    My brain is fuzzy on this, so if I made a boo-boo
    here, please correct me.
     
    xarax, Oct 17, 2003
    #2
    1. Advertising

  3. "xarax" <> wrote in
    news:QmTjb.200$:

    >> I understand the rationale behind declaring function definitions such
    >> as
    >>
    >> int main() { return 0; } /* empty parentheses */
    >>
    >> obsolete, but I haven't been able to find out why Dennis Ritchie
    >> despised them enough to call them an "abomination." Comments and/or
    >> links appreciated.

    >
    > IIRC, the empty parens is the same as:
    >
    > int main(...);


    No, it doesn't. It means use the first-encountered usage to complete
    the prototype.

    --
    - Mark ->
    --
     
    Mark A. Odell, Oct 17, 2003
    #3
  4. Christopher Benson-Manica

    Dan Pop Guest

    In <bmosk3$phg$> Christopher Benson-Manica <> writes:

    >I understand the rationale behind declaring function definitions such as
    >
    >int main() { return 0; } /* empty parentheses */
    >
    >obsolete, but I haven't been able to find out why Dennis Ritchie despised them
    >enough to call them an "abomination."


    Please elaborate.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Oct 17, 2003
    #4
  5. Christopher Benson-Manica

    Dan Pop Guest

    In <Xns941775DCD8FB6CopyrightMarkOdell@130.133.1.4> "Mark A. Odell" <> writes:

    >"xarax" <> wrote in
    >news:QmTjb.200$:
    >
    >>> I understand the rationale behind declaring function definitions such
    >>> as
    >>>
    >>> int main() { return 0; } /* empty parentheses */
    >>>
    >>> obsolete, but I haven't been able to find out why Dennis Ritchie
    >>> despised them enough to call them an "abomination." Comments and/or
    >>> links appreciated.

    >>
    >> IIRC, the empty parens is the same as:
    >>
    >> int main(...);

    >
    >No, it doesn't. It means use the first-encountered usage to complete
    >the prototype.


    Nope, it doesn't. It means this definition/declaration doesn't
    provide a prototype for this function.

    You're *severely* confused if you believe that the the
    first-encountered usage has any relevance whatsoever. The following
    code does NOT require any diagnostic:

    void foo();
    ...
    foo(1);
    foo(1, 2);
    foo(1, 2, 3);

    although it's obvious that at most one of these calls can be correct.
    It's a clear case of undefined behaviour.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Oct 17, 2003
    #5
  6. Christopher Benson-Manica

    Derk Gwen Guest

    Christopher Benson-Manica <> wrote:
    # I understand the rationale behind declaring function definitions such as
    #
    # int main() { return 0; } /* empty parentheses */
    #
    # obsolete, but I haven't been able to find out why Dennis Ritchie despised them
    # enough to call them an "abomination." Comments and/or links appreciated.

    P'raps in comparison to how Algol 60 and 68 and Pascal and other such
    languages handle the same issue.

    --
    Derk Gwen http://derkgwen.250free.com/html/index.html
    God's a skeeball fanatic.
     
    Derk Gwen, Oct 17, 2003
    #6
  7. Dan Pop <> spoke thus:

    > Please elaborate.


    Basically, I want to know how Dennis Ritchie and the Standards Committee can
    arrive at diametrically opposed positions regarding empty parentheses. Why
    does Dennis believe the syntax should be retained? Presumably it isn't
    because he's a crackpot, because various important people (like Bjarne
    Stroustrup) agree with his reasoning.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Oct 17, 2003
    #7
  8. (Dan Pop) wrote in news:bmp4b3$b8r$:

    >>>> I understand the rationale behind declaring function definitions such
    >>>> as
    >>>>
    >>>> int main() { return 0; } /* empty parentheses */
    >>>>
    >>>> obsolete, but I haven't been able to find out why Dennis Ritchie
    >>>> despised them enough to call them an "abomination." Comments and/or
    >>>> links appreciated.
    >>>
    >>> IIRC, the empty parens is the same as:
    >>>
    >>> int main(...);

    >>
    >>No, it doesn't. It means use the first-encountered usage to complete
    >>the prototype.

    >
    > Nope, it doesn't. It means this definition/declaration doesn't
    > provide a prototype for this function.


    What should I have said?

    --
    - Mark ->
    --
     
    Mark A. Odell, Oct 17, 2003
    #8
  9. Christopher Benson-Manica

    P.J. Plauger Guest

    "Christopher Benson-Manica" <> wrote in message
    news:bmp75b$qgs$...

    > Dan Pop <> spoke thus:
    >
    > > Please elaborate.

    >
    > Basically, I want to know how Dennis Ritchie and the Standards Committee can
    > arrive at diametrically opposed positions regarding empty parentheses. Why
    > does Dennis believe the syntax should be retained? Presumably it isn't
    > because he's a crackpot, because various important people (like Bjarne
    > Stroustrup) agree with his reasoning.


    I believe the issue has been slightly misstated. The original C language
    that Ritchie developed had no mechanism for making the argument types a
    part of the function type. The C committee added what we call function
    prototypes to remedy what was widely perceived as a clear deficiency.
    (We modeled those prototypes largely on previous C++ work, but not entirely.
    For example, I had developed a commercial C compiler as early as 1975 that
    had something similar.)

    The quandary we then faced was what to do about backward compatibility.
    Ritchie stated a strong dislike for having two mechanisms that did much
    the same thing, only differently. The committee was sympathetic with that
    view, but had a practical problem to solve. So we left the 'T f()' notation
    to declare f as a function returning T with no constraints on argument
    types. We also added 'T f(void)' as a way of clearly stating that f was
    constrained to have no arguments, and the ... notation for a varying length
    argument list with no type constraints. The rules for mixing old and new
    style declarations and definitions we worked out to minimize surprises.
    (A major contribution was Sam Harbison's rule about implicit prototypes,
    which we quickly dubbed the Miranda Rule.)

    None of us liked having two similar but different rules for declaration.
    Many of us regretted parting company with C++ on the meaning of 'T f()'.
    Ritchie was gracious enough to acknowledge that what we did was probably
    necessary, however undesirable. I haven't heard the term 'abomination'
    applied to this situation (except possibly by C++ zealots) for nearly
    20 years now.

    P.J. Plauger
    Dinkumware, Ltd.
    http://www.dinkumware.com
     
    P.J. Plauger, Oct 17, 2003
    #9
  10. On Fri, 17 Oct 2003, Mark A. Odell wrote:
    >
    > (Dan Pop) wrote in news:bmp4b3$b8r$:
    > [Mark A. Odell wrote:]
    > >>
    > >>No, it doesn't. It means use the first-encountered usage to complete
    > >>the prototype.

    > >
    > > Nope, it doesn't. It means this definition/declaration doesn't
    > > provide a prototype for this function.

    >
    > What should I have said?


    From Dan's response, I gather that you should have said,
    "No, it doesn't. It means use the first encountered *prototype*
    to complete the prototype, and *until then* just assume that the
    user wants the default promotions applied to the arguments in
    any calls to that function."

    A function "usage" means a function call, I'd say:

    foo(1) foo("abcd")

    A function "prototype" means a prototype:

    int foo(int); void foo(const char *p) { }


    HTH,
    -Arthur
     
    Arthur J. O'Dwyer, Oct 17, 2003
    #10
  11. Arthur J. O'Dwyer wrote:
    >
    > On Fri, 17 Oct 2003, Mark A. Odell wrote:
    >>
    >> (Dan Pop) wrote in news:bmp4b3$b8r$:
    >> [Mark A. Odell wrote:]
    >> >>
    >> >>No, it doesn't. It means use the first-encountered usage to complete
    >> >>the prototype.
    >> >
    >> > Nope, it doesn't. It means this definition/declaration doesn't
    >> > provide a prototype for this function.

    >>
    >> What should I have said?

    >
    > From Dan's response, I gather that you should have said,
    > "No, it doesn't. It means use the first encountered *prototype*
    > to complete the prototype, and *until then* just assume that the
    > user wants the default promotions applied to the arguments in
    > any calls to that function."


    Still not quite right, I'm afraid. Going by the OP's example code
    we're talking about an empty argument list in a function /definition/.
    In this case the function is defined to take no arguments, and calls
    to the function which supply arguments have undefined behaviour (and
    so need not be diagnosed) unless there's a separate prototype in scope
    in which case such calls violate a constraint.

    Jeremy.
     
    Jeremy Yallop, Oct 17, 2003
    #11
    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. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    'AddressOf' operand must be the name of a method; no parentheses a

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    15
    Views:
    7,591
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Oct 19, 2004
  2. Replies:
    7
    Views:
    9,260
    Jeff Dillon
    May 17, 2006
  3. Memana
    Replies:
    1
    Views:
    325
    Alf P. Steinbach
    Jul 5, 2004
  4. Replies:
    44
    Views:
    965
    Timo Virkkala
    Jan 6, 2005
  5. Kamilche
    Replies:
    11
    Views:
    1,735
    Nick Coghlan
    Jan 8, 2005
Loading...

Share This Page