Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do C++ coders usually do moves explicitly or do they just rely on the compiler to do it?

We have this in some function:

BigClass big;
// prepare big somehow
OtherClass foo(std::move(big), maybe, other, params);
// know that we won't be using "big" after this.

Would most C++ coders these days actually put the move there to guarantee a move?

like image 538
user2015453 Avatar asked Feb 07 '13 19:02

user2015453


People also ask

Does C code need to be compiled?

C is a mid-level language and it needs a compiler to convert it into an executable code so that the program can be run on our machine.

How does C code works?

The C programming language works by writing your code into an executable file. The C compiler will take that executable and convert it in its entirety into machine code that will then be executed by your computer at runtime.

How C codes are compiled and executed?

For C programming language, it happens before a program starts executing to check the syntax and semantics of the code. The compilation process in C involves four steps: pre-processing, compiling, assembling, and linking then, we run the obtained executable file to get an output on the screen.

Why do programmers use compiler?

Compilers analyze and convert source code written in languages such as Java, C++, C# or Swift. They're commonly used to generate machine code or bytecode that can be executed by the target host system. Interpreters do not generate IR code or save generated machine code.


1 Answers

In your particular piece of code, either you move directly or there won't be a move at all. The compiler will never move out of an lvalue (that is not eXpiring).

like image 140
David Rodríguez - dribeas Avatar answered Sep 22 '22 07:09

David Rodríguez - dribeas