« first day (1489 days earlier)      last day (1364 days later) » 

2:52 AM
Can anyone explain data[read_pos++].~T();? Where T is a template
@JerryCoffin?
How can a dtor be explicitly called?
 
 
2 hours later…
4:49 AM
i recently read that destructors can be called explicitly but there is some problems when the object go out of it's scope because then the compiler will call again the destructor on an already destructoed object. I would also like to know more about this
 
 
2 hours later…
7:17 AM
You don't normally want to directly call the dtor of a local object. The most common use is in conjunction with placement new, which constructs an object at a specified address. It's also possible to destroy a local object, then create a new one in its place. This basically allows you to simulate assignment for a type that doesn't support assignment.
 
 
3 hours later…
10:32 AM
I understand why the following code doesn't run:

#include <iostream>
int main(){
int* p;
*p = 2;
return 0;
}
But if I add something irrelevant before, it runs just fine and I can print out *p and p with no problem.

#include <iostream>
int main(){
char k = 'a'; //only thing added
int* p;
*p = 2;
return 0;
}
Why does this happen ? Is it compiler issue ?
 
 
1 hour later…
11:40 AM
Runs fine.... that's called undefined behaviour
 
But what is the reason why the first code fails in running while the second code runs fine ?
 
11:54 AM
Who told you the second runs fine>
*?
It will till you show it on stage ;)
That is when it will show you a BSOD
 
Process returned 0(0x0) tells me it runs fine.
 
That's what happens ;)
@domocar1 That's what
 
But hold on a second
 
That is why it is called undefined behaviour
 
Why does adding a simple irrelevant line results in "Process returned 0(0x0)"
That is my question
 
11:56 AM
You are not getting the answer that's all
It will always result in Process returned 0
 
It does not in the first code
 
It should not
Don't think too much of it
 
.-.
I'm not overthinking about anything
It's just plain weird
Try it yourself if you don't believe me
 
@domocar1 Exactly
 
And if you get the same console message that means it's gotta be a compiler issue
I mean, the same console message in both cases
 
12:01 PM
@d4rk4ng31 might be different on his machine
that's the thing about undefined behavior, if you want to see why it doesn't crash use a debugger, look at the asm and inspect the uninitialized value
the same compiled binary even can work on one machine but not on the other if you rely on UB
 
I see, I didn't get what @d4rk4ng31 was saying
I expected crashes no matter what.
Now undefined behaviour actually makes sense
 
 
1 hour later…
1:08 PM
Are there conversions in C++ that doesn't produce temporary objects ?
 
1:40 PM
For example, conversion from int* to const int* ?
 
 
5 hours later…
6:47 PM
@domocar1 Uh, conversions that are based on references? int& to int const&
(idk)
 
 
3 hours later…
9:23 PM
Is that considered as a conversion ?
int x = 3;
int& rx = x;
const int& crx = rx;
Would it be right to call this a conversion ?
I've read this somewhere on the stack: "In C++ results of conversions are always rvalues (unless you convert to reference type)"
But I've never seen anyone calling reference binding of similiar types ( which does not invoke the temp. objects ) as a conversion.
Btw ty for answering, I was becoming hopeless after a few hours :/
 

« first day (1489 days earlier)      last day (1364 days later) »