Re: BSD Unix: Weird call to structure constructor in formatter.h
Alf P. Steinbach wrote:
* Gerhard Menzl:
Alf P. Steinbach wrote:
* James Kanze:
Most people (I think) don't consider them as such, because they do
more.
You're onto a slippery slope: an explicit call of a destructor does
about the same, complexity-wise, as an explicit call of a constructor.
I don't think so. An explicit call of a destructor doesn't free memory.
Yes, as I went on to discuss in the article you quoted from, allocation
related actions seem to be a dividing line for James (and now you).
Not allocation per se. It's more general. The dividing line is
simple: if the expression calls X, and only calls X, it can be
said to be, semantically at least, an explicit call of X. If it
does other things (allocating memory just happens to be the
example here), then it is not an explicit call of X (but that
doesn't mean that in some cases, X may be called).
It's rather mystifying to me.
It seems to be very much analogous to "all cars are cars, except Mazda
cars, they're not -- just -- because!". And when queried about the
fundamental difference of Mazda cars, well, one Mazda, the RX7 (IIRC),
had a Wankel engine. So? It's an engine. Doesn't matter that things
go a-round and a-round in there; things go 'round and 'round everywhere.
I think it's more a case of "all cars are cars, except a Boeing
747, because it flies." A Boeing 747 is also capable of rolling
on the ground under its own power, but it does more.
There are expressions that look like explicit constructor calls, but
they are not because they do more. On the other hand, expressions that
have the effect of direct constructor calls (i.e. in-place new) don't
look like ordinary function calls at all.
Sorry, there are expressions that look like explicit constructor calls
and really are: they're constructor calls, and they're explicit. This
has already been discussed, but perhaps a new round of discussion is
needed for each person.
That's because, to date, no one has been convinced. You seem to
be the only one trying to argue the position from a standards
point of view.
And on the other hand, placement new, which
looks like and which you state above has the effect of a direct
constructor call (note: difference between explicit and direct), is a
very indirect constructor call. In particular, it's unspecified whether
the constructor arguments are evaluated before or after the allocation
function is called (and that function can throw).
Not really. The placement new which I think Gerhard was
referring to (as you know, the expression has two different
meanings) is defined in the standard with a "throw()" exception
specifier, and is required to be a no-op. The semantic effects
are exactly those of explicitly calling the constructor. (The
syntax, of course, is another matter.)
Without understanding the indirectness of new and placement
new, this can be hard to grok.
Yes and no. I suppose that one could just learn that it's just
a wierd syntax for explicitly calling the constructor. Of
course, in that case, when one learned the general placement
new, one would wonder about the similarity of the syntaxes.
[...]
There's therefore no need to look to additional, imaginary constructor
properties to justify the statement that constructors can't be called
like other member functions.
I think that the problem is more complex. Consider something
like:
struct Toto {} ;
struct Titi { operator Toto() { return x ; } ; Toto x ; }
void f( Toto const& ) ;
void g()
{
Titi a ;
f( Toto( a ) ) ;
}
Is "Toto( a )", in the next to last line an explicit call to the
constructor. It's certainly an "explicit type conversion
(functional notation)".
If the authors of the standard chose this way of describing
things, there's a reason.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]