So there are copy semantics, move semantics and maybe more semantics that I don't know of. I have read articles about both but I still do not really get have a good definition of "semantics". As the name suggests, move semantics have something to do with moving things but why is it called move semantics?

The more clear version: What is the meaning of semantics in the context of programming? Example: Move and copy semantics.

  • 10
    "semantics" = "the meaning of".
    – Will Ness
    Jul 5 '17 at 12:04
  • 1
  • @WillNess I don't get it.
    – user8221510
    Jul 5 '17 at 12:06
  • 4
    "move semantics" = "what is the meaning of moving something? how is it done? in what situations? what are its pre- and post-conditions? what does it mean, to "move" something?"
    – Will Ness
    Jul 5 '17 at 12:08
  • 4
    How is this question "too broad"? It has exactly one definitive answer.
    – Galik
    Jul 5 '17 at 12:24

Semantics basically means "the meaning of".

It may help to look at a more familiar case to explain the term.


int a = 3;
int b = 5;

int c = a + b;

The value of a + b is 8 because the semantics of the + operator is to take the numerical sum of its operands.

Now consider this:

std::string a = "hello";
std::string b = "world";

std::string c = a + b;

The value of a + b is "helloworld" because the semantics of the + operator is to concatenate its operands.

The + operator, when used with std::string is said to have different semantics from when it is used with numerical types.

It has a different meaning.

Now consider copy and move semantics:

std::string a = "hello";
std::string b;

b = a; // b receives a copy of a's value

b = std::string("hello"); // the temporary value is moved into b

We have the same operator = which has a different meaning in different situations. Again we say is has different semantics.

The first case has copy semantics and the second case has move semantics.

  • Your examples could be extended to where int operator+(int, int) differs to std::string operator+(std::string, std::string, e.g. int d = b + a; assert(c == d); and std::string d = b + a; assert(c != d)
    – Caleth
    Jul 5 '17 at 12:24
  • Thanks. So "move semantics" simply means "things concerning movement"? Or is there something that I did not catch?
    – user8221510
    Jul 5 '17 at 14:12
  • Excellent. This is my accepted answer.
    – Ignorant
    Nov 30 '19 at 17:55

The word semantics is used to describe an underlying meaning of something.

You can say that an operation has the move semantics when it transfers an object state from one object to another. In reality of course what happens is some pointers are probably copied over and that's it, but semantically your object has been moved.

Another example is the ownership transfer, when the most important thing that is moved is the responsibility (i.e. the promise to release some resource). In that case from the computational point of view pretty much nothing happens, but semantically the ownership is transferred.

The same goes for copy semantics: you can say that passing an object to a function has copy semantics i.e. your object would be duplicated and the function will get a standalone copy with its own lifetime.

Another side of the coin is the syntax which is how you describe what you want following the rules of the language.

C++ has really flexible syntax - overloading operators, user-defined conversions, macros and what not, so almost any desirable semantics can be attached to any particular syntax.


Semantics is about the meaning of something. move-semantic is about the meaning of moving objects. Specifically, in this context, it tells you what it means to move something in C++. The semantic of moving is all about everything that is involved during a move operation.

read move-semantic as: what does it mean, what are the implications (and how do you achieve it ) of moving an object in a C++ program?

The following is a good answer that might help: What are move semantics?