Re: BSD Unix: Weird call to structure constructor in formatter.h
Alf P. Steinbach wrote:
* James Kanze:
Alf P. Steinbach wrote:
Syntax and semantics are two different things: don't confuse them.
And please stop propagating the myth [no constructor calls] quoted above.
The problem is that the source of this particular myth is the
standard.
If the standard said that outright, or logically implied it, then the
standard would be inconsistent,
So what else is new.
as it refers to source code expressions
as constructors calls in numerous places -- including, in addition to
the two places I quoted, the definition of default constructor, which is
normative text.
You mean, like in ?12.1/2: "[...]; however an explicit type
conversion using the functional notation (5.2.3) will cause a
constructor to be called to initialize an object." As in, e.g.,
the next to the last line in this sequence:
struct Toto
{
Toto() ;
} ;
struct Titi
{
Toto myToto ;
operator Toto() { return myToto ; }
} ;
extern void f( Toto const& ) ;
void g()
{
Titi t ;
f( Toto( t ) ) ; // <<< Note function style cast.
}
(Where Toto doesn't even have a constructor of the desired
type.)
I think we could agree that the standard could use a little more
consistency.
However, I agree with you that the standard is the source of the myth.
See below.
I agree that it would be much clearer if there were
the concept of explicitly calling a constructor, but for various
reasons, the standard doesn't do this.
Sorry, that statement is in direct conflict with the standard, which
/defines/ default constructors in terms of the concept of a source code
expression that is a constructor call.
Where do you see that? It says (both in the original C98 and in
N2134) that "A default constructor for a class X is a
constructor of class X that can be called without an argument."
(?12.1/5) There is no reference to any source code expression,
or who does the calling. And there's no doubt in anyone's
mind, I think, that constructors do get called, in certain
contexts (where a variable has been allocated and must be
initialized).
In particular, ?12.1
says "Constructors do not have names"; it further goes on to
specify a special declarator syntax using the constructor's
class name. Outside of that syntax, however, you cannot name a
constructor,
Yes, that is the syntax level. And IMO that little word-play trick
(apparently used to provide special look-up rules) is a bit inconsistent
since the standard does refer to destructor names[1].
There's a difference. ~Toto is not Toto. For that matter,
``operator Toto'', in the above example, is also the name of a
function. ``Toto'', alone, is the name of a type, however, and
not the name of the constructor.
I think it should
have been corrected since it's a source of much confusion & misery.
I don't see any significant differences in the latest working
draft.
--
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! ]