implicit declaration in C++ considered harmful
Joe Buck
jbuck@synopsys.com
Wed Apr 8 02:13:00 GMT 1998
I'd like to nuke the implicit declaration of functions in C++. This
thoroughly broken feature cannot be turned off.
Yes, you get a warning, and you can make warnings errors, but the problem
is that if a user forgets to declare a function, or mistypes it, cascades
of dozens of errors can result, because g++ declares it as int foo(...),
then objects to all class objects passed to this function, then objects
to use of the result in a context where ints aren't allowed, etc.
Or else the file compiles normally, and errors aren't noticed until link
time.
Now, in the early days of C++ when we were all basically C programmers,
this hangover from K&R C may have been desirable. But the time is overdue
to kill this sucker; these days, chances are good that most functions
I write are going to get a class object passed to them, so the default
declaration just can't be right.
First, it should be an error, not a warning. Second, the compiler should
insert an error node, not a function returning integer, so that we don't
get a cascade of errors.
Is there anyone who really wants the existing behavior?
Joe
More information about the Gcc
mailing list