Is their representation part of their definition, referring to specific C ++ types?

In both of his books

The C ++ Programming Language, 2013 (4th Edition) and The C ++ Journey, 2013

Bjarne Stroustrup writes:

Types such as complex ... are called concrete types because their representation is part of their definition .

Which to some extent clarifies the above statement:

In this they resemble built-in types. In contrast, an abstract type is a type that completely isolates the user from the implementation of the Detail. To do this, we decouple the interface from the view and discard the real local variables. Since we don't know anything about the representation of an abstract type (even its size), we have to allocate objects in free storage and access them via references or pointers.


Questions

In the phrase "... their presentation is part of their definition."

  • What is the meaning of the type view ? That is, a representation of what exactly: the mock object in memory? Private and public data that is of type? Or something else?

  • What is the point of type definition ?

  • Are these typical view values ​​and type definitions C ++ related?


I decided to do some more research and I checked other sources. I first looked through the ISO / IEC 14882: 2011 specifications, which specify the requirements for C ++ programming language implementations, and then through other sources.

Question for announcement 1

I could not find anything like "type representation" or "type representation" in the ISO specifications. Instead, there are two members associated with objects:

An object representation of an object of type T

is a sequence of N objects unsigned char

occupied by an object of type T

, where N is equal to sizeof(T)

.

An object value representation is a set of bits that contain the value of a type T

. For trivially copyable types, a value representation is a set of bits in an object representation that defines a value that is one discrete element of a specified set of values.

So it seems to me that the type representation of a type has no generally accepted meaning in the ISO standards.

Ok. Maybe this is something outside the ISO standards? Let's see what Standard Basic C ++ Linux 3.1> Chapter 7. C ++ Class Representations> 7.1. The C ++ Data View says:

The object file generated by the compilation process for a C ++ program must contain several closely related internal objects or Class Components to represent each C ++ class . Such objects are not visible as part of the source code. The following table describes the high level class components.

Table Class Components

Object ....................... Contains
= ---------------------------------------- =
Class Data ................... Class members
Virtual Table ................ Information needed to dispatch virtual functions,
                             access virtual base class subobjects and to access
                             the RTTI information
RTTI ......................... Run-Time Type Information used by the typeid and
                             dynamic_cast operators, and exception handlers
Typeinfo Name ................ String representation of Class name
Construction Virtual Table ... Information needed during construction and
                             destruction of Classes with non-trivial
                             inheritance relationships.
VTT .......................... A table of virtual table pointers which holds the
                             addresses of construction and non-construction
                             virtual tables.

Question 2

Again, I could not find an explicit explanation of the type definition in the ISO specifications .

Instead, I found the following:

Ad can contain one or more names in the translation unit ... A class declaration introduces the class name into the scope in which it is declared ... The declaration is a definition if [I removed things not directly related to the class declaration] ... this is the name declaration class ...

Here's Microsoft's interpretation of the same thing:

C ++ Declarations - MSDN - Microsoft

Ad ... one or more names in the program. Declarations can occur more than once in a program ... Declarations also serve as definitions, except when the declaration : ...; Is a declaration of a class name without the following definition, for example class T ; ...

and

C ++ definitions - MSDN - Microsoft

A definition is a unique specification of an object or variable, function, class, or rewriter. Since definitions must be unique, a program can only contain one definition for a given program item. There can be an ambiguous correspondence between declarations and definitions. There are two cases where a program item can be declared and undefined : a function is declared but never refers to a function call or an expression that takes a function address. The class is used only in such a way that its definition is not required to be known.

Examples:

struct S;    // declares, but not defines S
class T {};  // declares, and defines T
class P { int a;};  // declares, and defines P, P::a

      

Conclusions:

Candidate # 1 answer:
proposed by Jonathan Wackeli
(below is my understanding)
The phrase " Types such as complex ... are called concrete types because their representation is part of their definition " should be interpreted and understood as follows: ● their definition (= type) is a technical C ++ term, the meaning of which is conditional and can be found in the C ++ specifications.
their (= type) representation(according to Jonathan Wackeli) is not a technical C ++ term in this context, but its meaning is easy to understand by anyone who understands English well (and this is probably my guess, was previously exposed to a lot of C ++ codes and texts) ... A type representation in this context means "properties that define what a type is and what it does", that is,
"for a concrete type: the type and location of its members",
"for an abstract type: its member functions and their observable behavior"
● Then the whole phrase (we're talking about concrete classes) is translated into:
" Types such as complex ... are called concrete types because the types and layouts of their members are part of their definition. "
I think this interpretation makes sense, is clear, and fits well with what follows in the BS books.

Please correct me if there is anything wrong here **

+3


source to share


2 answers


QUESTIONS: in the phrase "... their presentation is part of their definition." 1) What is the point of type representation ? (i.e. the WHAT representation is accurate: mock object in memory or private and public data that is of a type or whatever) 2) What is the point of defining a type ? 3) Are these typical view values ​​and type definitions C ++ related?

You are asking for the meaning of terms that Stroustup does not use in the text you quoted!

He's not trying to define a formal specification for a type-representation term as the C ++ standard does, he writes prose that is more informal. All references to technical terms you have dug up are misleading and have no direct meaning.

(i.e. the WHAT representation is accurate: an in-memory layout of an object, or private and public data that is of a type, or whatever)

Yes, both of the things you mention. For a particular type, the properties that define what it is and what it includes include the type and location of its members. that is, how it is represented in the source code.

For an abstract class, the properties that define what it is and what it does are its member functions and their observable behavior. The details of how this produces the observable behavior are not necessarily important and sometimes not even visible in the source code, because you are actually using some particular class defined in another piece of code and only using it through an abstract interface.



Edit: Judging from the comments you wrote below, you obviously missed that I tried to give you an answer. What I wrote above is about properties that define what a type is and what it does . This is "type definition".

If you needed to write user-friendly C ++ type documentation, how would you define it?

For a particular type, you can describe the types of its members and define some of its properties in terms of properties of its members. for example "A std::complex<float>

stores two terms float

that represent the real and imaginary parts of a complex number." This means that it std::complex<float>

can only store complex numbers with the same precision as float

, i.e. Its accuracy is determined by the fact that it is represented by two members float

.

For an abstract class, you would describe the behavior of its member functions, which are likely to be virtual

, so you describe it in terms of an interface rather than in terms of implementation details.

But they are not formal terms, I think you are mistaken regarding them as strict technical conditions. He just used words with their usual English meaning.

+2


source


You go to vegetable

dinner for the evening . Wait ... a vegetable? The word "vegetable" defines something exactly, but it has no idea. Someone will definitely ask you which vegetable. Thus, the vegetable is an abstract concept .

So now you order several potatoes

and onions

. Well, they define some properties and present themselves well enough that you can find them in the store. Potatoes and onions constitute a concrete type representation with well-defined properties and behaviors.



Try to write two classes following this analogy. You can connect to valuerepresentation is part of their definition.

0


source







All Articles