int f(void)

  • Follow


I've just been reading
http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.4
"the f(void) style has been called an "abomination" by Bjarne
Stroustrup, the creator of C++, Dennis Ritchie, the co-creator of C,
and Doug McIlroy, head of the research department where Unix was born."

http://technetcast.ddj.com/tnc_program.html?program_id=9
reveals that Stroustrup was convinced that this style was an
abomination by Ritchie and McIlroy.  But does anyone know the exact
reason why they consider it to be so?

Thanks,
Stuart


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply studennett (5) 5/19/2005 1:20:13 AM

On 18 May 2005 21:20:13 -0400, "studennett" <studennett@hotmail.com>
wrote in comp.lang.c++.moderated:

> I've just been reading
> http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.4
> "the f(void) style has been called an "abomination" by Bjarne
> Stroustrup, the creator of C++, Dennis Ritchie, the co-creator of C,
> and Doug McIlroy, head of the research department where Unix was born."
>
> http://technetcast.ddj.com/tnc_program.html?program_id=9
> reveals that Stroustrup was convinced that this style was an
> abomination by Ritchie and McIlroy.  But does anyone know the exact
> reason why they consider it to be so?
>
> Thanks,
> Stuart

I think the real reason for making "int f();" and "int f(void);"
equivalent in C++ was so that countless newbies to the language would
get bitten by this:

class ac { int i; };

int main()
{
   ac a();
   a.i = 2;
   return 0;
}

....since due to the ambiguity, the first line inside main() is the
declaration of a function named a that returns an instance of class as
by value, and not a default initialized instance of class a.

Actually, the form "int a (void);" is required in C and allowed in
C++.  Calling it an "abomination" and deprecating its use is no more
than a style issue, and one that has consequences as shown above.

-- 
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply Jack 5/19/2005 9:19:31 AM


studennett wrote:
> I've just been reading
> http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.4
> "the f(void) style has been called an "abomination" by Bjarne
> Stroustrup, the creator of C++, Dennis Ritchie, the co-creator
> of C, and Doug McIlroy, head of the research department where
> Unix was born."

> http://technetcast.ddj.com/tnc_program.html?program_id=9
> reveals that Stroustrup was convinced that this style was an
> abomination by Ritchie and McIlroy.  But does anyone know the
> exact reason why they consider it to be so?

What sort of exact reason are you looking for?

In some ways, it's an esthetic judgement, and so personal.
Still, there are some universals, even in taste, and I can't
really imagine anyone liking it.  It's illogical and
unorthogonal; a function declaration consists of the return
type, followed by the function name, followed by a comma
separated list of its parameters, in parentheses.  And
obviously, an empty list means no parameters.  Whereas void is a
type, and f(void) *should* declare a function taking a single
parameter, of void type (which, of course, isn't possible, so
the thing should be illegal).

Historically, one glaring defect in C was that you didn't
declare the parameters of a function.  So if you wrote f() in
one place, f(32) in another, and f("what",3.14) in yet a third,
that was fine with the compiler (even though f really expects a
pointer to a struct).  Stroustrup corrected this in early C++;
his correction, however, did represent a radical break with C
compatibility.  The ANSI C committee decided to accept his
correction (with modifications), BUT... in order to maintain
compatibiliy, f() had to mean "no information given" with
regards to the function parameters, and not "no parameters". So
they invented the abomination.

Of course, the real abomination to begin with was C, not
requiring function parameters to be correctly declared.

--
James Kanze                                           GABI Software
Conseils en informatique orient�e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply kanze 5/19/2005 1:51:44 PM

Jack Klein wrote:
> On 18 May 2005 21:20:13 -0400, "studennett"
> <studennett@hotmail.com> wrote in comp.lang.c++.moderated:

> > I've just been reading
> > http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.4
> > "the f(void) style has been called an "abomination" by
> > Bjarne Stroustrup, the creator of C++, Dennis Ritchie, the
> > co-creator of C, and Doug McIlroy, head of the research
> > department where Unix was born."

> > http://technetcast.ddj.com/tnc_program.html?program_id=9
> > reveals that Stroustrup was convinced that this style was an
> > abomination by Ritchie and McIlroy.  But does anyone know
> > the exact reason why they consider it to be so?

> I think the real reason for making "int f();" and "int
> f(void);" equivalent in C++ was so that countless newbies to
> the language would get bitten by this:

> class ac { int i; };

> int main()
> {
>    ac a();
>    a.i = 2;
>    return 0;
> }

> ...since due to the ambiguity, the first line inside main() is
> the declaration of a function named a that returns an instance
> of class as by value, and not a default initialized instance
> of class a.

> Actually, the form "int a (void);" is required in C and
> allowed in C++.  Calling it an "abomination" and deprecating
> its use is no more than a style issue, and one that has
> consequences as shown above.

Actually, originally, "int a(void);" was not allowed.  And of
course, both forms are perfectly legal in C, but with different
meanings.  Something like:

    int
    main()
    {
        char* a() ;
        char* p = a( 3.14 ) ;
        return 0 ;
    }

is perfectly legal C.

The real problem, of course, is the C declaration syntax.

--
James Kanze                                           GABI Software
Conseils en informatique orient�e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply kanze 5/19/2005 1:52:09 PM

> What sort of exact reason are you looking for?

Just the reason that they gave :) but it's not too important anyway,
since it's just a 'style' issue.


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply studennett 5/23/2005 4:54:51 PM

4 Replies
167 Views

(page loaded in 0.076 seconds)

Similiar Articles:













7/14/2012 3:33:46 AM


Reply: