Topic: Q: result of new someClass[0] ?


Author: tspeuker@cip.informatik.uni-erlangen.de (Thomas Peuker)
Date: 1997/08/14
Raw View
Hi all,

I wonder what is the result of allocating an array of zero objects?
A NULL-pointer? Or undefined/unpredictable?

Thanks, Tom
--
Thomas Peuker, Computer Science Student, FAU Erlangen, Germany
Email: tspeuker@informatik.uni-erlangen.de    Phone: ++49 9131 206113
WWW: http://wwwcip.informatik.uni-erlangen.de/user/tspeuker
---
[ 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: Steve Clamage <stephen.clamage@Eng.Sun.COM>
Date: 1997/08/15
Raw View
Thomas Peuker wrote:
>=20
> I wonder what is the result of allocating an array of zero objects?
> A NULL-pointer? Or undefined/unpredictable?

>From section 5.3.4 "New":

"When the value of the expression in a direct-new-declarator is
zero, the allocation function is called to allocate an array with
no elements. The pointer returned by the new=ADexpression is non=ADnull.=20
[Note: If the library allocation function is called, the pointer
returned is distinct from the pointer to any other object. ]"

So you will get a non-null pointer, but you cannot dereference
it, since it doesn't point to an object.

--=20
Steve Clamage, stephen.clamage@eng.sun.com
---
[ 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
]