Topic: default initialization of built-in types


Author: comeau@panix.com (Greg Comeau)
Date: 1997/05/11
Raw View
In article <33733C2D.3135@crd.lotus.com> Mark Sashihara <Mark_Sashihara@crd.lotus.com> writes:
>One feature of java I like is that data members of built-in types (int,
>pointer, etc) have reasonable default values (usually 0) when they
>aren't explicitly initialized by the constructor.  The lack of this
>feature seems to be a frequent cause of bugs in C++ - has it been
>considered for adoption for the standard?

The implicit init'r to 0 of statics goes 1/2 way to this.  However,
IMO, the lack of the feature is not the bug.  The bug is the lack of
an explicit initializer.  A default initializer is not a solution,
it is another bug, precisely because things such as "reasonable default"
is generally unreasonable.  I never bought that 0 could ever possibly
be generally acceptable.

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
               Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
 Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: "Paul D. DeRocco" <strip_these_words_pderocco@ix.netcom.com>
Date: 1997/05/11
Raw View
Mark Sashihara wrote:
>
> One feature of java I like is that data members of built-in types (int,
> pointer, etc) have reasonable default values (usually 0) when they
> aren't explicitly initialized by the constructor.  The lack of this
> feature seems to be a frequent cause of bugs in C++ - has it been
> considered for adoption for the standard?

It's fairly costly, since it is extremely common to declare variables of
built-in types without initializers, and simply assign to them later on
in the function. You might argue that the compiler should be smart
enough only to zero out those that it can see might be used before
they're assigned to, but the very same intelligence is used in existing
compilers to warn the user about using a variable before it's been set.

--

Ciao,
Paul

(Please remove the "strip_these_words_" prefix from the return
address, which has been altered to foil junk mail senders.)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Mark Sashihara <Mark_Sashihara@crd.lotus.com>
Date: 1997/05/09
Raw View
One feature of java I like is that data members of built-in types (int,
pointer, etc) have reasonable default values (usually 0) when they
aren't explicitly initialized by the constructor.  The lack of this
feature seems to be a frequent cause of bugs in C++ - has it been
considered for adoption for the standard?
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]