Dave Moore wrote in news:306d400f.0404290800.574b1f15@posting.google.c om
in comp.lang.c++:
[color=blue]
> Rob Williscroft <rtw@freenet.co.uk> wrote in message
> news:<Xns94D9AEB29866BukcoREMOVEfreenetrtw@130.133 .1.4>...[color=green]
>> Dave Moore wrote in
>> news:306d400f.0404280144.22bd8d7@posting.google.co m in comp.lang.c++:
>>[color=darkred]
>> > "John Harrison" <john_andronicus@hotmail.com> wrote in message
>> > news:<c6m7pc$dir2s$1@ID-196037.news.uni-berlin.de>...
>> >> "Sam Wilson [Bentley]" <sam.wilson@bentley.com> wrote in message
>> >> news:408E8107.724EB6EE@bentley.com...
>> >> > If you pass a C++ object by value as an argument to a function
>> >> > which has
>> >> >
>> >> > a variable-length argument list (...), the MSVC7 C++ compiler
>> >> > does not call the object's copy constructor and will not
>> >> > complain if the copy constructor is private.
>> >> >
>> >> > 1) Is this part of the C++ language definition? What is the
>> >> > thinking behind it?
>> >>
>> >> Kind of, the C++ standard just says that such behaviour is
>> >> undefined.
>> >>
>> >
>> > Please cite chapter and verse from the Standard when making such
>> > assertions. In this case I think you are incorrect ... the rules
>> > for arguments without parameters (5.2.2/7) don't say anything
>> > explicit about the copy constructor. Basically they imply that an
>> > rvalue argument that has class type will be used "as-is" ... which
>> > I assume[/color]
>>
>> This makes no sense at all, how can an rvalue (or anything else for
>> that matter) be passed without copying ?[/color]
>
> Well, I guess I see your point, but then how is a pass-by-value
> argument of POD-type handled in a variadic function call? In Jerry
> Coffin's response to my post in this thread, he said that a ctor
> should be called "to initialize the parameter", but as I understand it
> from 5.2.2/7 (which IMO is kind of vague here), there *is* no
> parameter in a variadic function call (for arguments matching the ...
> anyway), only an argument.[/color]
The paramiter is the argument that the function recieves i.e. the paramiter
is that which the argument initializes and that which va_arg() recieves.
[color=blue]
> So is my statement below about deferring
> the copy constructor until the va_arg call correct?[/color]
No. The POD class has an implicitly generated copy constructor (memberwise
copy) that is used to intialize something implementation defined, could
be stack, registers, a combination of both or maybe something else, that
will be accessable by the va_* macros in the called function.
Because in general we don't know how the va_* macro's work, show's one
reason why a class with user defined copy constuctor can't be a POD.
[color=blue]
>[color=green][color=darkred]
>> > to mean that the call to the copy constructor is deferred until the
>> > call to va_arg in the function body.[/color][/color]
>
> OTOH, maybe there is some effect of the statement " .. lvalue to
> rvalue conversion ... will be performed" in 5.2.2/7 that I am not
> seeing?[/color]
An example of the lvalue to rvalue conversion here is:
int &f()
{
static int i = 10;
return i;
}
int main()
{
std::printf( "%d", f() );
}
f() returns an lvalue, the conversion to rvalue ( int & -> int )
is done by making a copy. Its done by initializing the paramiter.
If the lvalue to rvalue conversion wern't done then the compiler
would be required to pass the reference, *not* what std::printf
expects.
[color=blue]
> I would say that a POD-type object passed by value is an
> rvalue, but I remember seeing somewhere in the Standard (I can't find
> it anymore) that objects of class type are always passed to functions
> as lvalues.
>[/color]
You've miss remembered, the only why an lvalue can be passed to
a function is if the function takes a reference paramiter.
void f( int ¶m );
'param' is an lvalue and *importantly* its the lvalue that
was passed.
void f( int const &cparam );
'cparam' is an lvalue, but strangly it might be "bound" to
an rvalue, go figure :).
[color=blue]
> Please help me out of my confusion.
>[/color]
Hopt it helped.
[color=blue]
>
> P.S. I expect there is more info on this in the C-Standard, but I
> don't have a copy of that.[/color]
I've no doubt it would be educational. But IIUC the C++ standard
say's everything it needs to about function calls and doesn't defer
to the C standard.
Rob.
--
http://www.victim-prime.dsl.pipex.com/