Kindly log in to use this feature. We’ll take you to the login page automatically.
LoginDigital Marketing Facebook Marketing API 3 years ago
User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Kindly log in to use this feature. We’ll take you to the login page automatically.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
manpreet
Best Answer
3 years ago
_x000D_ In C++, non-trivial destructor -> must have addressable storage (An illustration of a point in @MaximEgorushkin's answer using @harold's example in a comment.) If you compile: struct Foo { int bar; }; Foo test(Foo byval) { return byval; } you get: test(Foo): mov eax, edi ret i.e. the Foo object is passed to test in a register (edi) and also returned in a register (eax). but this is actually an exception to the rule. Generally, the C++ standard requires an object's storage to be addressable. Only if there's a trivial destructor [CITATION NEEDED] are we allowed the "as-if shortcut" of passing data through the registers. When the destructor is not trivial (like the std::unique_ptr example of OP's) - addressable storage means we have to put the object on the stack. This is true even if the destructor does not at all use the object's address! Thus if you compile: struct Foo2 { int bar; ~Foo2() { } }; Foo2 test(Foo2 byval) { return byval; } you get: test(Foo2): mov edx, DWORD PTR [rsi] mov rax, rdi mov DWORD PTR [rdi], edx ret with useless loading and storing.