Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "semantics" mean? and why are "move semantics" named as such, instead of any other term?

Tags:

c++

semantics

In Cpp, the "move semantics" of an object refers to the concept that "move but not copy the object to a newer", but the word "semantics" really confuse me.

What is the difference between the "semantics" and "function"? How to use this word correctly? If I realize a method called "max(A,B)", could we say "I realize a max semantic"? If I coding a object called "list", could we say "I realize a sequence storage semantic"?

like image 926
Jianjie Avatar asked Sep 14 '21 14:09

Jianjie


People also ask

What is a move semantic?

Move semantics is a set of semantic rules and tools of the C++ language. It was designed to move objects, whose lifetime expires, instead of copying them. The data is transferred from one object to another. In most cases, the data transfer does not move this data physically in memory.

Where is move semantics used?

Move semantics allows you to avoid unnecessary copies when working with temporary objects that are about to evaporate, and whose resources can safely be taken from that temporary object and used by another.

Are move semantics important?

Move semantics allows an object, under certain conditions, to take ownership of some other object's external resources. This is important in two ways: Turning expensive copies into cheap moves. See my first answer for an example.

How are Move semantics implemented?

Move semantics aim to avoid the copying of data from temporary objects by instead stealing the memory location of where the object resides. This behaviour is implemented through the use of a move constructor and move assignment operator that act only on rvalue references.

What is the meaning of semantics?

In its broader sense, semantics is the study of meaning. We normally use it to denote a misunderstanding caused by the connotations of our choice of words. It is beyond question that the words we choose matter, but this is too narrow a definition of meaning.

What does it mean to not argue about semantics?

If you hear someone say, 'Let's not argue about semantics ,' that person is speaking of the different meanings and nuances we may derive from a given conversation or passage. Nuance refers to the subtle differences in meaning or shades of meaning we associate with words.

Is talking semantics all we do?

Talking semantics is all we do, but this is not what we mean by “talking semantics.” Like everything in linguistics, speaking of semantics in lay terms risks becoming a conceptual loop, a riddle. What is the meaning of meaning? But that is always the paradoxical nature of language.

Why do we have semantics for human languages?

We have semantics for human languages, but also for logics, or computer languages. In the case of human languages, to have a semantics for a language is to be able to assign a meaning to every word in that language, and then to compute the meanings of sentences based on the meanings of those words and how they are put together.


Video Answer


1 Answers

"Semantics" is the meaning or interpretation of written instructions. It is often contrasted to "syntax", which describes the form of the instructions. For example, an assignment foo = bar has the same form in many programming languages, but not necessarily the same meaning. In C++ it means copy, in Rust it means move, and in Java or Python it means copy the object reference.

"Move semantics" applied to C++ syntax such as assignment or passing parameters to functions means that that syntax is or can be interpreted as object move as opposed to object copy. Semantics is not a synonym for "function", so "max semantics" doesn't make much sense.

Other examples where the word can be applied is reference semantics as opposed to value semantics, or "short-circuit semantics" (of the && and || operators) as opposed to evaluating all clauses. Basically, anything where there are multiple possible meanings of what you wrote, and you need to name and pinpoint the correct one.

like image 182
user4815162342 Avatar answered Nov 15 '22 05:11

user4815162342