S
Scott Danzig
I'm curious.. let's say you had:
int val = 5;
int a()
{
return val;
}
int &b()
{
return val;
}
void c()
{
int i;
int &j;
i = a(); // Line 1
i = b(); // Line 2
j = a(); // Line 3
j = b(); // Line 4
}
I'm wanting to know the details of what's copied when in each of the 4
lines. Here's my guess:
Line 1: (2 int copies, 0 address copies)
val is copied onto the stack as a return value, then copied again into
i's storage space.
Line 2: (1 int copy, 1 address copy)
an address of val is copied onto the stack as a return value, then the
value it points to is copied into i's storage space.
Line 3: (1 int copy, 1 address copy)
I'm not sure about this one. It looks like val is copied onto the
stack as a return value, but then the address of that return value is
stored as a reference. In this case, I'd think the value should be
undefined, no?
Line 4: (0 int copies, 2 address copies)
an address to val is copied onto the stack as a return value, then the
address is copied to be i's new address.
Can someone confirm/deny/clarify this? Thanks.
- Scott
int val = 5;
int a()
{
return val;
}
int &b()
{
return val;
}
void c()
{
int i;
int &j;
i = a(); // Line 1
i = b(); // Line 2
j = a(); // Line 3
j = b(); // Line 4
}
I'm wanting to know the details of what's copied when in each of the 4
lines. Here's my guess:
Line 1: (2 int copies, 0 address copies)
val is copied onto the stack as a return value, then copied again into
i's storage space.
Line 2: (1 int copy, 1 address copy)
an address of val is copied onto the stack as a return value, then the
value it points to is copied into i's storage space.
Line 3: (1 int copy, 1 address copy)
I'm not sure about this one. It looks like val is copied onto the
stack as a return value, but then the address of that return value is
stored as a reference. In this case, I'd think the value should be
undefined, no?
Line 4: (0 int copies, 2 address copies)
an address to val is copied onto the stack as a return value, then the
address is copied to be i's new address.
Can someone confirm/deny/clarify this? Thanks.
- Scott