c++ - The term value is mentioned in the definition of an entity, but what is a value? -


in c++ standard there following definition of entity can found:

[basic]/3 ( http://eel.is/c++draft/basic#3 ):

an entity value, object, reference, function, enumerator, type, class member, bit-field, template, template specialization, namespace, parameter pack, or this.

what value in context?

is there rule of standard using term entity, make difference if didn't consider value entity?

is pr-value expression value?

the c++ language standard infamously vague formally defining "object" , "value" is. there efforts improve (e.g. n4430), not before c++17.

at present, 1 of definitions of "object" "a region of storage". term "value" never defined; taxonomy of lvalues , rvalues not have "value" common ancestor, rather "expression".

for time being, offer following commentary.

every value object: every value has type, , type object type, type of object. conversely, every object has value. distinction in usage: when talking object, storage of entity under consideration, while values result of evaluation of expression. value of object obtained evaluating object, or more precisely evaluating expression value object (tautologically). in yet other words, values subjects of computation, , objects means values stored.

the distinction comes play when consider rules concern accessing object through value. evaluating id-expression names object yields lvalue is object, , canonical way of accessing object. can produce other values , access object way:

unsigned char x; x = 10;                                   // "x" expression , lvalue reinterpret_cast<signed char &>(x) = 20;  // access through different lvalue 

(note incidentally variables can, need not objects (they can references), evaluating id-expression names variable produces value, hence object. conversely, not objects variables (e.g. new expression produces object not variable), object types can in principle type of variable (subject constructibility , destructibility).)

values more diverse objects, too. consider simple example:

int a; int b = 10; b = a; 

the last line contains 2 objects, several values: b lvalue of type int object of variable b. expression a on rhs lvalue of type int, being object of variable a. value not suitable assignment. first, there implicit conversion, lvalue-to-rvalue conversion, produces new value. value still same object, prvalue, , that value used in evaluation of assignment.

finally, have temporaries: temporary values or temporary objects? until standard sly , called them "temporaries", made more precise in few places , says "temporary objects". purpose of evaluation not matter value stored, , fact storage , lifetime temporary matters, "temporary object" appropriate. note though cannot take address of temporary object built-in address-of operator, such objects can of course have addresses (which can exported e.g. via class member function returning this). it's not valid beyond limited lifetime of temporary object.

in nutshell: objects , values different facets of same thing, viewed different perspectives: respectively perspectives of evaluation on 1 side , storage, access , lifetime on other.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -