« first day (1285 days earlier)      last day (1558 days later) » 

user6461957
2:10 AM
@genaray, b/c you declared it as a rval reference? And 10 is a temporary object?
 
nwp
8:34 AM
@genaray Because rVal is an lvalue. The quick rule is that everything you can take the address of is an lvalue and &rVal compiles, so it's an lvalue. &10 doesn't compile, so it's not an lvalue. One reason is that inside foo you may want to use rVal twice and it would suck if it always gets destroyed of first use, so you have to do that explicitly.
It makes a bit more sense if you stop using lvalue and rvalue and use "temporary" instead. Temporaries die anyways, like in 10; the int there dies at the end of the ;. For int &&rVal = 10; the rVal stays, it is not about to get destroyed. You can think of std::move as "cast to temporary", meaning you explicitly treat a non-temporary as a temporary.
 
 
3 hours later…
11:14 AM
int c1='\141t'; // how this is printing 24948
int c2='\141\t'; //and this as 24841
can anybody help here
?
 
nwp
I can't find the reference, but the TLDR is that wide characters have implementation-defined values and MSVC does it differently than gcc and clang.
Not to be confused with wchar_t.
 
@sunil
'\141' = 0x61 't'=0x74
0x6174 = 24948
'\141' = 0x61 '\t'=0x09
0x6109 = 24841
 
11:34 AM
@PeterT '\' mean hexadecimal sequence ?
 
no, it's just "start escape sequence", if it's just '\NNN', where N is a numbers then it's octal
'\x61' would be hexadecimal
 
ok so you converted \141 (is octal) to hexadecimal , that is 0x61 and same for others
 
yes, just because it's easier to see how they get 'added' together in hexadecimal representation
 
@PeterT thanks :)
 
 
2 hours later…
user6461957
1:17 PM
>>> the int there dies at the end of the ;
Does that mean `10;` dies, but `int &&rVal = 10;` doesn't?
Since `rVal` holds a reference to a `temporary`?

(`rVal` has an address and is thus an lvalue and references a "temporary", right?)

What sense does it make to hold a reference to a "temporary" (rvalue) of a fundamental type? What difference does that make?:

int x = 42;
int &&y = 42;
 
nwp
1:28 PM
It doesn't make any difference here. The point of the && is to say "I want a reference to a temporary that I can break without anyone noticing." 42 is such a temporary. int i = 0; is not. So int x = i; is fine, it makes a copy, int &&y = i; is an error, cannot bind rvalue reference to a non-temporary.
 
@d03 it makes more sense when you have an object that is usually immutable but has methods to allow the manipulation of temporaries to prevent extraneous copying.
 
user6461957
@nwp I find your mental cue, i.e., using "temporary" instead of "rvalue"/"lvalue" helpful. I also find it useful to not think about whether or not it is a pass by reference or value. It is just a copy. You always have copies no matter what you do.

A copy of a pointer/reference is usually less costly for non-fundamental types and a copy of values is usually costly for non-fundamental types.

(That confused me a lot when I was learning about it years ago, but not anymore...)
 
user6461957
void f(int c) - 4 bytes - is cheaper than void f(int *c) - 8 bytes.
void f(MyVector v) - 12 bytes or more - is costly than say void f(MyVector &v) - 8 bytes
 
nwp
My mental model also says you always pass by value and void f(int &ir) simply takes a reference by value. Sadly the standard disagrees and says references bind and are not objects with a value, so technically it's not correct. But the difference is irrelevant until you get into pedantic discussions, so I haven't had a need to correct that.
@d03 Be careful with assuming performance here. Often there are side-effects. If you pass in MyVector then the compiler knows nobody else can see it and can optimize the hell out of it. If you pass MyVector & then it must stay valid for whoever passed it in and the compiler is more restricted. Making statements about performance without measuring is really dangerous and often wrong.
 
user6461957
IOW: Always measure and verify instead of making assumptions about behavior?
 
nwp
1:43 PM
Benchmark and profile if you really care about performance. But it's also fine to just not care or to delay caring until later.
When it comes to behavior/correctness you gotta read the code and know the rules. Trying it out is dangerous because that relies on stable behavior and undefined behavior tends to not always be stable.
 
 
2 hours later…
3:29 PM
I have read that we can do multi targetting in visual studio. I have a static library which i need to change to platform toolset 140 to make use of magic static. The activex component which will create the object in static lib will be 120. Will this object make use of thread safe static initialization?
 

« first day (1285 days earlier)      last day (1558 days later) »