简体   繁体   中英

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

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"?

"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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM