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: Neatest way to get the end pointer? - comp.lang.cAnd here's UB in action: muntyan@munt10:/tmp$ cat alias.c #include <stdio.h> int func (void) { int f =3D 9; *(short*)&f =3D 2; return f; } int main (void ... Const constructor - comp.lang.c++.moderatedvoid foo(int* pi) { A myA(pi); // - 'all over the place' // do stuff to A } void goo(const int* pic) { // A myA(pic ... extern typedef struct - comp.lang.c=Do you know if you have =int f(int a) ={int name[200]; = return name ... lang.asm.x86 Anyway, here is a small example: #include <signal.h> typedef void sig_t(int ... Set JComboBox 's JTextField into JFormattedTextField, how? - comp ...... EventListenerList(); return clone; } protected void fireActionPerformed() { ActionEvent e = null; Object[] pairs = listenerPairs(); for (int i ... glOrtho & gluUnProject troubles... - comp.graphics.api.opengl ...... right; float left; float cx; // pan offset float cy; } OrthoView; OrthoSide side = FRONT; OrthoView orthoViews[3]; int oldPos[2], newPos[2]; void init() { int s ... Windows server, Unix client, connection refused on client connect ...... connect with timeout using select // 3. set socket to BLOCKING againg int my ... addr = sock_addr; // Set non-blocking if( (arg = fcntl(sockremote, F_GETFL, NULL ... BufferedReader vs NIO Buffer - comp.lang.java.programmer ...... FILE_NAME); for(int i = 0; i < TOT; i++) { f.write((i % 256)); } } } abstract class GenericReadTest { public void doTest ... problem with mixed c and fortran code - comp.lang.fortran ...... end $ cat c.c #include <stdlib.h> #include <stdio.h> unsigned char * fcall_1_(unsigned char *); int main(void) { unsigned char c1,c2,*cp1,*cp2; c1='F ... NIOS-II+LAN91C111 - comp.arch.fpgavoid s91_senddata(SMSC smsc, unsigned char *data, int len) { u_long base = smsc->regbase; /* device base address */ #if 0 unshort *word ... Re: Using SSE 128 bit movs From One Memory Location To Another ...// gcc -std=3Dc99 -o cmagic cmagic.c // --- #include <time.h> #include <string.h> #include <stdlib.h> #include <stdio.h> int main( void ) { time_t alpha; time_t beta ... is f(void) deprecated in modern C and C++ - Stack OverflowI'm currently refactoring/tidying up some old C code used in a C++ project, and regularly see functions such as . int f(void) which I would tend to write a int main() vs. int main(void) - FogBugzGiven the choice : int main(void); --OR--void main(void); Although the latter is NOT ANSI/ISO C, but is still common nonetheless in embedded development. 7/14/2012 3:33:46 AM
|