Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!pacbell.com!tandem!zorch!vsi1!octopus!sjsumcs!horstman From: horstman@mathcs.sjsu.edu (Cay Horstmann) Newsgroups: comp.lang.c++ Subject: Re: Why no renew Message-ID: <1991Mar23.164302.10931@mathcs.sjsu.edu> Date: 23 Mar 91 16:43:02 GMT References: <281@nazgul.UUCP> <1991Mar14.042611.14921@mathcs.sjsu.edu> <12132@pasteur.Berkeley.EDU> Organization: San Jose State University - Math/CS Dept. Lines: 49 In article <12132@pasteur.Berkeley.EDU> jbuck@galileo.berkeley.edu (Joe Buck) writes: >In article <1991Mar14.042611.14921@mathcs.sjsu.edu>, horstman@mathcs.sjsu.edu (Cay Horstmann) writes: >|> I repeat my request that operator new should default to initializing the >|> memory with the logical 0 value for the type allocated (almost always an >|> all-0 bit pattern, but then who knows how 0 pointers or 0.0 floats are >|> represented on some crazy systems.) ANSI, are you listening? > >How are you going to implement this? operator new is handed a size_t >object and returns an object of type void. It doesn't know what type >it's supposed to return. Or do you want to make the "default" operator >new special (preventing a user from writing something similar)? I am not proposing to build this into operator new. Just like arrays of classes get initialized AFTER operator new is called, arrays of non-class objects would be initialized afterwards. You could still supply your own global operator new. > >Even if you could solve the technical problems, I'm still against it; >it will just lead to lazy programming and subtle bugs (people will >stop worrying about initializing every object member). Now I agree it would be AWFUL if people started worrying about initia- lizing every object member. For that reason, constructors should be BANNED from the language. Get real. Automatic initialization is one of the great features of C++. People have enough other things to worry about when writing programs. > >Next you'll be asking for a guarantee that when I write > >void foo (int arg1) { > char byteArray[BIGBUF]; > int intArray[INTBUF]; > ... >} > >that byteArray and intArray be initialized to all zeros as well. If not, >why not? Why should creating an array with new be different from making >automatic variables? I am not going to argue this. It is not a problem I often have when pro- gramming C++. It would be an incompatible change from C. I restrict my request to operator new which doesn't exist in C, and for which an alter- native exists (calling malloc) when the cost of zeroing out is considered excessive. Cay