Topic: Object creation by malloc
Author: litb <Schaub-Johannes@web.de>
Date: Thu, 7 May 2009 12:07:45 CST Raw View
Why isn't the creation of the following object mentioned in 1.8
[intro.object]? The list looks like it is intended to be exhaustive.
While the only place where one could assume the following object be
created by is "... by the implementation when needed...", which refers
to 12.2 and which talks about temporary objects so it's not what the
below object is created by.
struct C { int a; };
int main() {
C *c = static_cast<C*>( malloc(sizeof *c) );
c->a = 0;
}
It is just doing what 3.8 [basic.life] describes - steps which have to
be done in order to start lifetime for some object.
I think it should be somehow incorporated into the list of 1.8.
Another option is to change the definition of object in another way. C+
+ attributes also a type to the object-entity itself (contrary to C).
We could make the type optional. Introducing an object without type
(which is created by malloc) and whose type as a property is
determined when lifetime starts (for the case where the object is
created manually by 3.8/1) according to 3.8/1 and 3.8/3 (where the
latter says that the properties ascribed to objects throughout the
Standard are only valid during the lifetime of an object) would then
be possible i think.
I also find the wording of 3.8/1 confusing. There are many, many types
that the above created malloc'ed region of storage would be correctly
aligned and sized for. Does that mean that this region of storage is
occupied by objects with all those types?
What do you think about it? Do i miss anything important? Any idea
what the wording of 3.8/1 is intended to say?
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]