Topic: Now is the time (Was: Improvements on C++?)


Author: swf@tools3teradata.com (Stan Friesen)
Date: 14 Dec 92 17:25:41 GMT
Raw View
In article <5349@holden.lulea.trab.se>, jbn@lulea.trab.se (Johan Bengtsson) writes:
|> Is this true?  Are you all depending on "default int", you poor sods?
|> I for one _never_ depend on that rule.

I *used* to.  I don't anymore, nowadays I always declare the type of a function.
(If anything I tend towards a 'default void' style, in C, except I usually even
declare that).

And, in C++, where all function *must* be declared, I *always* declare the
return type.

--
sarima@teradata.com   (formerly tdatirv!sarima)
  or
Stanley.Friesen@ElSegundoCA.ncr.com




Author: hendrik@vedge.com (Hendrik Boom)
Date: 14 Dec 92 15:28:54 GMT
Raw View
jbn@lulea.trab.se (Johan Bengtsson) writes:
: Johan Bengtsson (jbn@lulea.trab.se) wrote:
: Fergus James HENDERSON (fjh@munta.cs.mu.OZ.AU) wrote in comp.lang.c++:
: :
: : The compiler should warn about any code that has a high likelyhood of being
: : a programming error, except where such code is actually necessary in some
: : cases and cannot easily be rewritten to avoid the warning.
:
: I absolutely agree.  How about this one:
:
: // myFile.cc
: class MyClass {
: //...
: };
: IMPLEMENT_TYPE(MyClass);
:
: "IMPLEMENT_TYPE" is a macro defined in a header file, and guess what?
: I forgot to #include it.  Does the compiler warn about this?  No!
: It thinks it is a function prototype with return type "int"!
: How wonderful...

But C++ allows another place where you can leave out the int.
How about:

typedef int Foo;

class MyClass {
 MyClass(Foo())
};

Is this a constructor taking a Foo-valued function argument,
or a redeclaration of Foo in an inner scope as a method returning a MyClass?
--
-------------------------------------------------------
Try one or more of the following addresses to reply.
at work: hendrik@vedge.com,  iros1!vedge!hendrik
at home: uunet!ozrout!topoi!hendrik




Author: jbn@lulea.trab.se (Johan Bengtsson)
Date: 10 Dec 92 20:01:45 GMT
Raw View
Johan Bengtsson (jbn@lulea.trab.se) wrote:
Fergus James HENDERSON (fjh@munta.cs.mu.OZ.AU) wrote in comp.lang.c++:
:
: The compiler should warn about any code that has a high likelyhood of being
: a programming error, except where such code is actually necessary in some
: cases and cannot easily be rewritten to avoid the warning.

I absolutely agree.  How about this one:

// myFile.cc
class MyClass {
//...
};
IMPLEMENT_TYPE(MyClass);

"IMPLEMENT_TYPE" is a macro defined in a header file, and guess what?
I forgot to #include it.  Does the compiler warn about this?  No!
It thinks it is a function prototype with return type "int"!
How wonderful...

Isn't it time to get rid of the extremely silly default int rule?
Benefits (like you didn't know):

- Better compiler error reports; the compiler knows that the first
  identifier in a declaration is a type name, and can give more
  intelligent diagnostics than "syntax error".

- Confusion between macro calls and function prototypes eliminated.

- Clearer programs (anyone think "int" is the "natural" type
  these days?).

- (Much?) cleaner C++ grammar.


Below are some comments from Sep 91 by Mr. Stroustrup (his view may of
course have changed; I am including it only as basis for my comments).

BS>
BS>  >   Does anybody still believe that the
BS>  >  C "default int" rule is a Good Thing?
BS>
BS> I don't think I know anybody that really likes that rule. However,
BS> getting rid of a rule that is been used in essentially every C and
BS> C++ program isn't easy - however beneficial it might be for the C++
BS> grammar.

Is this true?  Are you all depending on "default int", you poor sods?
I for one _never_ depend on that rule.

BS>
BS>  >  Actually, I wouldn't complain if ANSI C (and C++) defined
BS>  >  "default int" as an anachronism, removing it in some future
BS>  >  standard.
BS>
BS> Neither would I, but that doesn't guarantee that it will happen.
BS> Standard committees are - as they should be - very reluctant to
BS> make decisions that breaks people's programs. Fading out the
BS> ""default int" rule would at best be a very slow process.

And therefore we should begin that process now.  It is such a simple
and desirable change (IMO).  Warnings for a while, then errors.
Good compilers will have switches to enable compilation of the then
obsolete code.

I think Standard C++ should call "default int" an anachronism.


John MAX Skaller said a few weeks ago:
JMS>
JMS> We can keep "default int" for extern "C" function return types .
[...]
JMS> Anyone who used default int
JMS> for a C++ function deserves to have their code broken!

These are good points (IMHO).


What does it take to make this happen?  I am hoping the committee
members will come to their senses and make this straightforward change.
Perhaps a little user pressure on compiler vendors might do it?  Why
don't we send a complaint to our vendor each time "default int" bites
us (I think I will)?

--
--------------------------------------------------------------------------
| Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
| Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490  |
--------------------------------------------------------------------------
--
--------------------------------------------------------------------------
| Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
| Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490  |
--------------------------------------------------------------------------