2

I've come across the definition of the value/object representation of type T. 3.8/4 gives one to us:

The object representation of an object of type T is the sequence of N unsigned char objects taken up by the object of type T, where N equals sizeof(T). The value representation of an object is the set of bits that hold the value of type T. For trivially copyable types, the value representation is a set of bits in the object representation that determines a value, which is one discrete element of an implementation-defined set of values.

I can't imagine the difference of these definitions for a trivially compyable types between for any other types. What excatly restriction applies to a trivially copyable type? I would like to look at an example, if any, of such distinction.

  • 1
    Not sure if enough for an answer but if an object isn't a trivially copyable one it might have to do some resources cleanup (and in very low-level contexts that isn't just plain simple and might rely on fixed addresses). – Marco A. Sep 14 '14 at 07:22
  • Possible duplicate of [Value representation of non-trivially copyable types](https://stackoverflow.com/questions/12773640/value-representation-of-non-trivially-copyable-types) – Language Lawyer Feb 24 '19 at 00:30

1 Answers1

1

If an object isn't a trivially copyable one it might have to do some resources initialization/cleanup (and in very low-level contexts that isn't just plain simple and might rely on fixed addresses).

Having two different objects which think they both have acquired an hardware resource is a recipe for disaster.

Marco A.
  • 43,032
  • 26
  • 132
  • 246
  • Is the _value_ an abstraction of the standard? I mean, the value is a property of an object according to c++ object model described in 1.8. Right? –  Sep 14 '14 at 07:34
  • I believe you can only specify that as in §3.9.4 if the object is a trivially copyable one. With non-trivially copyable ones the set space can't be enforced: it's implementation-defined (and might be extremely large as well) – Marco A. Sep 14 '14 at 07:52
  • It seems I'm beginning to understand. That's an object of not trivially copyable type has no value or it has no value to copy?I thing the latter is true, because of _The value representation of an object is the set of bits that hold the **value of type T.**_ –  Sep 14 '14 at 10:18
  • Exactly, that passage only holds for trivially copyable objects – Marco A. Sep 14 '14 at 10:22