Topic: Explicit constructor calls (was new question)
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Tue, 14 Dec 1993 13:03:42 GMT Raw View
jamshid@ses.com (Jamshid Afshar) writes:
>Neither the ARM or the June WP require (allow?) the
>implementation to define in <new.h> an overloaded `operator new()'
>taking a void pointer.
That is true, but the June WP is not the standard and neither is the ARM.
The ARM in particular says almost nothing about the standard library.
I don't think that you can infer from them that final standard
won't include such a function in <new.h>. The committee must
look at existing practice, not just at the ARM. Both of the C++
compilers which I can lay my hands on (Cfront and g++) do
include the function in <new.h>.
>If the user wants to use such a function he or
>she must define it.
This is not true with Cfront or g++.
>Some implementations do define the above function in <new.h>. I don't
>know if these implementations will drop the function in future
>releases or if ANSI/ISO is considering requiring it.
It's very unlikely that these implementations will drop the function in
future releases, because it would break quite a lot of existing code.
For the same reason, it's unlikely that the committee would force these
implementations to drop the function from <new.h>. This leaves the
committee with two choices: either require them to include it, or leave
it implementation dependant. The latter would be a very unworkable
situation, so I hope that the committee will require implementations to
declare the function in <new.h>.
Leaving it up to the user to implement the standard placement
operator new() would also make it difficult to combine libraries,
since operator new() might be defined multiple times by different
libraries.
Does anyone know whether the committee has considered this issue?
--
Fergus Henderson fjh@munta.cs.mu.OZ.AU
Author: kanze@us-es.sel.de (James Kanze)
Date: 14 Dec 1993 14:04:03 GMT Raw View
In article <CHwtvD.4IE@ses.com> jamshid@ses.com (Jamshid Afshar)
writes:
|> Right. WP 5.3.3: "The new-placement syntax [a parenthesized
|> expression following `new'] can be used to supply additional arguments
|> [to an `operator new()']".
|> >>and it is
|> >>NOT necessary to overload new yourself (unless you want to do something
|> >>special) - the default one is fine.
|> >You do need to #include <new.h>, though.
|> There is no default placement operator new nor is there necessarily
|> only one. Neither the ARM or the June WP require (allow?) the
|> implementation to define in <new.h> an overloaded `operator new()'
|> taking a void pointer. If the user wants to use such a function he or
|> she must define it. Also, the user may define any number of
|> allocation functions taking any number or types of parameters following
|> the `size_t' parameter.
|> Some implementations do define the above function in <new.h>. I don't
|> know if these implementations will drop the function in future
|> releases or if ANSI/ISO is considering requiring it.
My copy of the draft (Sept. 28, 1993) defines placement new in section
17.1.1.3.
I believe that this was actually decided a long time ago. For various
reasons, most of the library decisions were not appearing in earlier
versions of the draft.
--
James Kanze email: kanze@us-es.sel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
Author: jamshid@ses.com (Jamshid Afshar)
Date: Sun, 12 Dec 1993 06:54:48 GMT Raw View
Redirected to comp.std.c++.
In article <9334421.29611@mulga.cs.mu.oz.au>,
Fergus Henderson <fjh@munta.cs.mu.OZ.AU> wrote:
>nikki@trmphrst.demon.co.uk (Nikki Locke) writes:
>>In article <CHMu25.MEA@ses.com> jamshid@ses.com writes:
>>> The proper way to explicitly call a constructor on a raw chunk of
>>> memory is using an overloaded `operator new()':
>>>
>>> void* operator new(size_t, void* p) { return p; }
>>> task* ptask = new (buf) task; // okay
>>
>>As far as I am aware, this is called "placement operator new",
Right. WP 5.3.3: "The new-placement syntax [a parenthesized
expression following `new'] can be used to supply additional arguments
[to an `operator new()']".
>>and it is
>>NOT necessary to overload new yourself (unless you want to do something
>>special) - the default one is fine.
>You do need to #include <new.h>, though.
There is no default placement operator new nor is there necessarily
only one. Neither the ARM or the June WP require (allow?) the
implementation to define in <new.h> an overloaded `operator new()'
taking a void pointer. If the user wants to use such a function he or
she must define it. Also, the user may define any number of
allocation functions taking any number or types of parameters following
the `size_t' parameter.
Some implementations do define the above function in <new.h>. I don't
know if these implementations will drop the function in future
releases or if ANSI/ISO is considering requiring it.
Jamshid Afshar
jamshid@ses.com