Saturday, January 14, 2023

Inside the c++ object model pdf free download

Inside the c++ object model pdf free download

Name already in use,Iklan Tengah Artikel 1

Web downloads Views KB Size Report This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site WebDownload Original PDF This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, Web · Inside the C++ Object Model focuses on the underlying mechanisms that support object-oriented programming within C++: constructor semantics, temporary WebDownload Inside the C++ Object Model PDF book author, online PDF book editor Inside the C++ Object Model. Download and stutter books online, ePub / PDF online / Audible Webebook/inside the c++ object blogger.com Go to file. Cannot retrieve contributors at this time. MB. Download ... read more




Explains the basic implementation of the object-oriented features and the trade offs implicit in those features. Examines the impact on performance in terms of program transformation. Provides abundant program examples, diagrams, and performance measurements to relate object-oriented concepts to the underlying object model. Previously, he served as a Distinguished Consultant at the Jet Propulsion Laboratories JPL. After Bell Laboratories, Stan worked at Disney Feature Animation, originally as principal software engineer, then as software technical director on Fantasia Object Member Efficiency Section 3. Pointer to Data Members Chapter 4. The Semantics of Function Section 4. Varieties of Member Invocation Section 4. Virtual Member Functions Section 4.


Pointer-to-Member Functions Section 4. Inline Functions Chapter 5. Semantics of Construction, Destruction, and Copy Presence of a Pure Virtual Destructor Presence of a Virtual Specification Presence of const within a Virtual Specification A Reconsidered Class Declaration Section 5. Object Construction without Inheritance Section 5. Object Construction under Inheritance Section 5. Object Copy Semantics Section 5. Object Efficiency Section 5. Semantics of Destruction Chapter 6. Runtime Semantics Section 6. Object Construction and Destruction Section 6. Operators new and delete Section 6. Temporary Objects Chapter 7. On the Cusp of the Object Model Section 7. Templates Section 7. Exception Handling Section 7. Runtime Type Identification Section 7. Efficient, but Inflexible? Ru-Brd Ru-Brd Copyright The frontispiece art is an engraving Knight, Death and the Devil by Albrecht Dürer, — Courtesy, Museum of Fine Arts, Boston, Massachusetts. Gift of Mrs. Horatio Greenough Curtis in Memory of her Husband, Horatio Greenough Curtis.


The photograph on the back cover is by David Remba. Extracts on pages — are from the Journal of C Language Translation, Vol. Copyright , I. Levine, Trumansburg, New York. Reprinted by permission of the publisher. Senior Editor: Tom Stone Associate Editor: Debbie Lafferty Associate Production Supervisor: Patricia A. Oduor Copyeditor: Diane Freed Proofreader: Bunny Ames Art Editing Supervisor: Meredith Nightingale Senior Manufacturing Coordinator: Judith Y. Sullivan Library of Congress Cataloging-in-Publication Data Lippman, Stanley B. cm Includes bibliographical references and index.


Object-oriented programming Computer science I. Title: C plus plus object models ZA CL58 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. It was during the Simplifier's design period that I conceived of and began working on this book. What was the Foundation project? It was an exciting project, both for the work we were doing and for the people doing the work: Bjarne, Andy Koenig, Rob Murray, Martin Carroll, Judy Ward, Steve Buroff, Peter Juhl, and myself.


Barbara Moo was supervising the gang of us other than Bjarne and Andy. Barbara used to say that managing a software group was like herding a pride of cats. Internally, we called it Grail, as in the quest for, etc. It seems a Bell Laboratories tradition to mock one's most serious intentions. Grail provided for a persistent, semantic-based representation of the program using an object-oriented hierarchy Rob Murray developed and named ALF. Within Grail, the traditional compiler was factored into separate executables. The parser built up the ALF representation. Each of the other components type checking, simplification, and code generation and any tools, such as a browser, operated on and possibly augmented a centrally stored ALF representation of the program. The Simplifier is the part of the compiler between type checking and code generation.


Bjarne came up with the name Simplifier; it is a phase of the original cfront implementation. What does a Simplifier do between type checking and code generation? It transforms the internal program representation. There are three general flavors of transformations required by any object model component: 1. Implementation-dependent transformations. These are implementation-specific aspects and vary across compilers. Under ALF, they involved the transformations of what we called "tentative" nodes. For example, when the parser sees the expression fct ; it doesn't know if this is a an invocation of a function represented or pointed to by fct or b the application of an overloaded call operator on a class object fct.


By default, the expression is represented as a function call. The Simplifier rewrites and replaces the call subtree when case b applies. Language semantics transformations. Code and object model transformations. These include support for virtual functions, virtual base classes and inheritance in general, operators new and delete, arrays of class objects, local static class instances, and the static initialization of global objects with nonconstant expressions. An implementation goal I aimed for in the Simplifier was to provide an Object Model hierarchy in which the object implementation was a virtual interface supporting multiple object models. These last two categories of transformations form the basis of this book. Does this mean this book is written for compiler writers? No, absolutely not. The direct support for object-oriented programming provided within the language 2. The second aspect is barely touched on in any current text, with the exception of brief discussions within [ELLIS90] and [STROUP94].


Except for some minor details, this should reflect the final form of the language. This allows for extremely fast dispatch of a virtual invocation, although at the cost of runtime flexibility. The underlying mechanisms by which to implement the Object Model are not prescribed by the language, although the semantics of the Object Model itself make some implementations more natural than others. Virtual function calls, for example, are generally resolved through an indexing into a table holding the address of the virtual functions. Must such a virtual table be used? An implementation is free to introduce an alternative mechanism. Moreover, if a virtual table is used, its layout, method of access, time of creation, and the other hundred details that must be decided, are all decisions left to each implementation. Having said that, however, I must also say that the general pattern of virtual function implementation across all current compilation systems is to use a class-specific virtual table of a fixed size that is constructed prior to program execution.


The primary reason is because my experience has shown that if a programmer understands the underlying implementation model, the programmer can code more efficiently and with greater confidence. Determining when to provide a copy constructor, and when not, is not something one should guess at or have adjudicated by some language guru. It should come from an understanding of the Object Model. This book is partially an attempt to lay out as precisely as I can the kinds of overhead that are and are not inherent in the various Object facilities such as inheritance, virtual functions, and pointers to class members. Here is an excerpt from his response: I have heard a number of people over the years voice opinions similar to those of your colleagues.


This is of course not true. It is this sort of "myth and legend" that leads to opinions such as those held by your colleagues…. Finding the right balance [between abstraction and pragmatism] requires knowledge, experience, and above all, thought. Static initialization provides an interesting case in point. It does not, however, prescribe how that is to get done. The solution is called static initialization; the actual implementation depends on the degree of support provided by the environment. The original cfront implementation not only presumed no environment support. It also presumed no explicit platform target. The only presumption was that of being under some variant of UNIX. Our solution, therefore, was specific only to UNIX: the presence of the nm command.


The CC command a UNIX shell script for portability generated an executable, ran the nm command on the executable—thereby generating a new. c file—compiled the. c file, and then relinked the executable. This was called the munch solution. This did the job by trading compile-time efficiency for portability. Eventually, however, users chaffed under the compile- time overhead. The next step was to provide a platform-specific solution: a COFF-based program referred to as the patch solution that directly examined and threaded the program executable, thus doing away with the need to run nm, compile, and relink.


COFF was the Common Object File Format for System V pre-Release 4 UNIX systems. Both of these solutions are program-based, that is, within each. c file requiring static initialization cfront generated an sti function to perform the required initializations. Targeted for a specific platform and operating system, this compiler was able to effect a change in the System V link editor: a new initialize section that provided for the collection of objects needing static initialization. This extension of the link editor provides what I call an environment-based solution that is certainly superior to a program-based solution. So any generalization based on the cfront program-based solution would be misleading. How is this book to maintain a balance, then? If subsequent implementation models evolved as an attempt to solve perceived problems with the original cfront model, as, for example, with support for virtual inheritance, I present a discussion of the historical evolution.


Whenever I speak of the traditional implementation model, I mean, of course, Stroustrup's original design as reflected in cfront and which has provided a pattern of implementation that can still be seen today in all commercial implementations, even if only as a "reaction against. It includes a brief tour of the Object Model, illustrating the current prevailing industry implementation without looking too closely at multiple or virtual inheritance. This is fleshed out in Chapters 3 and 4. Chapter 2, The Semantics of Constructors, discusses in detail how constructors work. It discusses when constructors are synthesized by the compiler and what that means in practical terms for your program's performance. Chapters 3 through 5 contain the primary material of the book. Chapter 3, The Semantics of Data, looks at the handling of data members. Chapter 4, The Semantics of Function, focuses on the varieties of member functions, with a detailed look at virtual function support. Chapter 5, Semantics of Construction, Destruction, and Copy, deals with support of the class model and object lifetime.


Program test data is discussed within each of these chapters, where our performance expectations are compared against actual performance as the representations move from an object-based to object-oriented solution. Chapter 6, Runtime Semantics, looks at some of the Object Model behavior at runtime, including the life and death of temporary objects and the support of operators new and delete. Chapter 7, On the Cusp of the Object Model, focuses on exception handling, template support, and runtime type identification. At least, this has proved to be so in the various public presentations of this material I have given as it has evolved.


Ru-Brd Ru-Brd A Note on Program Examples and Program Execution The use of program code in this text serves two primary purposes: 1. To provide test cases by which to measure the relative cost of various language features In neither case is the code intended to represent models of production-quality programming. I am not, for example, suggesting that a real 3D graphics library represents a 3D point using a virtual inheritance hierarchy although one can be found in [POKOR94]. All the test programs in the text were compiled and executed on an SGI Indigo2xL running version 5. CC is cfront Release 3. NCC is version 2. The times were measured as the average user time reported by the UNIX timex command and represent 10 million iterations of the test function or statement block.


Both cfront and now the Edison Design Group's front-end reportedly characterized by Bjarne as the son of cfront are not platform specific. Rather, they are generic implementations licensed to over 34 computer manufacturers including Cray, SGI, and Intel and producers of software environments including Centerline and Novell, which is the former UNIX Software Laboratories. Benchmark performance numbers can be found in nearly any "compiler shoot-out" product review in the trade press. Ru-Brd Ru-Brd Acknowledgments One reason people write books is to set down and share their expertise with others. A second, more selfish reason is to enlarge on and fine tune that expertise. A third is to provide for the public acknowledgment of those who provide the foundation for one's work.


I owe a deep debt of gratitude to many former colleagues at Bell Laboratories without whose encouragement and insight little or nothing of this work could have been accomplished. In particular, Barbara Moo, Andy Koenig, and Bjarne Stroustrup have challenged and supported me throughout the years. Warm appreciation also goes to the Grail gang—Steve Buroff, Martin Carroll, Rob Murray, and Judy Ward—which has been a foundation for many years. Michael Ball, now at SunPro, generously shared his expertise both through e-mail exchanges and an in-depth review of the text. Doug Schmidt, Cay Horstmann, and Steve Clamage also provided tough, thoughtful reviews of the manuscript that were invaluable in helping me push the manuscript's development forward.


Jonathan Shopiro taught me a great deal while we worked together at Bell Laboratories; nuggets of his insight are scattered throughout the text. In addition, I'd like to acknowledge my current foundation here at Walt Disney Feature Animation: Michael Blum, Nhi Casey, Shyh-Chyuan Huang, Scott Dolim, Elena Driskill, Ed Leonard, David Remba, Cary Sandvig, and Dave Tonnesen. Chyuan, Scott, and Elena provided thoughtful readings on various versions of the text. Appreciation also goes to M. Turner, Kiran Joshi, Scott Johnston, Marcus Hobbs, and, finally, to the Technology Division management of Dean Schiller and Paul Yanover.


They have all helped to make my first year here at Disney sparkle a bit more brightly. This material has been given at a great many public presentations during the more than two years I have worked on it. The resultant feedback has proved of immense help in crafting and revising the material. Deep thanks also goes to my editor, Debbie Lafferty, who provided both sound counsel and unflagging support and always showed the good sense to laugh at my jokes. Portions of this text were originally published as columns in the magazine while I was editor. Peery, and Allen C. Peery, Allen C.


Robinson, and Michael K. and Alan D. O'Riordan, The Microsoft Object Mapping, Microsoft Corporation, Ru-Brd Ru-Brd Chapter 1. Object Lessons In C, a data abstraction and the operations that perform on it are declared separately—that is, there is no language-supported relationship between data and functions. We speak of this method of programming as procedural, driven by a set of algorithms divided into task-oriented functions operating on shared, external data. X pt, 0. There are many more or less convincing arguments for why the data encapsulation of an ADT or class hierarchy is better in the software engineering sense than the procedural use of global data such as that in C programs.


Those arguments, however, are often lost on programmers who are charged with getting an application up and running quickly and efficiently. The appeal of C is both its leanness and its relative simplicity. This doesn't mean they are not also considerably more powerful or, again in a software engineering sense, better. The answer is that there are no additional layout costs for supporting the class Point3d. The three coordinate data members are directly contained within each class object, as they are in the C struct. The member functions, although included in the class declaration, are not reflected in the object layout; one copy only of each non-inline member function is generated. Each inline function has either zero or one definition of itself generated within each module in which it is used.


The Point3d class has no space or runtime penalty in supporting encapsulation. There is also additional overhead under multiple inheritance in the conversion between a derived class and its second or subsequent base class. Ru-Brd Ru-Brd 1. That is, how do we model the various flavors of data and function members? A Simple Object Model Our first object model is admittedly very simple. In this simple model, an object is a sequence of slots, where each slot points to a member. The members are assigned a slot in the order of their declarations. There is a slot for each data or function member. This is illustrated in Figure 1. Simple Object Model In this simple model, the members themselves are not placed within the object. Only pointers addressing the members are placed within the object. Doing this avoids problems from members' being quite different types and requiring different amounts and sometimes different types of storage. Members within an object are addressed by their slot's index.


The general size of a class object is the size of a pointer multiplied by the number of members declared by the class. A Table-driven Object Model For an implementation to maintain a uniform representation for the objects of all classes, an alternative object model might factor out all member specific information, placing it in a data member and member function pair of tables. The class object contains the pointers to the two member tables. The member function table is a sequence of slots, with each slot addressing a member. The data member table directly holds the data.


This is shown in Figure 1. Figure 1. The SOM object model also relies on this two table model [HAM95]. Nonstatic data members are allocated directly within each class object. Static data members are stored outside the individual class object. Static and nonstatic function members are also hoisted outside the class object. Virtual functions are supported in two steps: 1. A table of pointers to virtual functions is generated for each class this is called the virtual table. A single pointer to the associated virtual table is inserted within each class object traditionally, this has been called the vptr. The setting, resetting, and not setting of the vptr is handled automatically through code generated within each class constructor, destructor, and copy assignment operator this is discussed in Chapter 5.


Its primary drawback is the need to recompile unmodified code that makes use of an object of a class for which there has been an addition, removal, or modification of the nonstatic class data members. The two table model, for example, offers more flexibility by providing an additional level of indirection. But it does this at the cost of space and runtime efficiency. iostream, for example, contains only a single instance of the virtual ios base class. How might a derived class internally model its base class instance? In a simple base class object model, each base class might be assigned a slot within the derived class object. Each slot holds the address of the base class subobject. The primary drawback to this scheme is the space and access-time overhead of the indirection. A benefit is that the size of the class object is unaffected by changes in the size of its associated base classes. Alternatively, one can imagine a base table model. Here, a base class table is generated for which each slot contains the address of an associated base class, much as the virtual table holds the address of each virtual function.


Each class object contains a bptr initialized to address its base class table. The primary drawback to this strategy, of course, is both the space and access-time overhead of the indirection. One benefit is a uniform representation of inheritance within each class object. Each class object would contain a base table pointer at some fixed location regardless of the size or number of its base classes. A second benefit would be the ability to grow, shrink, or otherwise modify the base class table without changing the size of the class objects themselves. A uniform access time could be gained by duplicating within the derived class a pointer to each base class within the inheritance chain. The tradeoff is in the additional space required to maintain the additional pointers.


This offers the most compact and most efficient access of the base class members. The drawback, of course, is that any change to the base class members, such as adding, removing, or changing a member's type, requires that all code using objects of the base class or any class derived from it be recompiled. The introduction of virtual base classes into the language at the time of Release 2. The original model of virtual base class support added a pointer into the class object for each associated virtual base class. Alternative models have evolved that either introduce a virtual base class table or augment the existing virtual table to maintain the location of each virtual base class see Section 3. How the Object Model Effects Programs In practice, what does this mean for the programmer? Support for the object model results in both modifications of the existing program code and the insertion of additional code.


Of course, you're not supposed to understand all these transformations at this point in the book. In the subsequent chapters, I look at the what and why of each of these, plus many more. Ideally, you'll look back, snap your fingers, and say, "Oh, yeah, sure," wondering why you were ever puzzled. For example, overloaded function resolution would be a lot simpler if there were not eight flavors of integer to support. In , my answer to this question was an unequivocal "never. At that time, this was one of those small philosophical points that one necessarily does not point out. However, it is one from which one gains some small admittedly quite small satisfaction when, well, when it is pointed out, usually as a question: "Hey, did you know? The keyword.


It's not used anywhere. Apparently its inclusion would have provided a transitional lifeline to make the programmer's rocky ascent less bruising. So much, then, for philosophy. Keywords, Schmeewords One answer to the question of when, if ever, you should use a struct declaration rather than a class declaration then, is whenever it makes one feel better. Although this answer does not achieve a high technical level, it does point out an important distinction that it is important not to make: the keyword struct by itself does not necessarily signify anything about the declaration to follow. We can use struct in place of class, but still declare public, protected, and private sections and a full public interface, as well as specify virtual functions and the full range of single, multiple, and virtual inheritance.


In the sense of its C usage, valid design reasons exist for its use. My point is simply that the keyword itself does not provide that distinction. The use of the keywords struct and class are interchangeable in providing a tag name. The conceptual meaning of the two declarations is determined by an examination only of the body of the declaration. In cfront, for example, the two keywords are replaced by the shared token AGGR in the parser. This information, however, was not used by the internal compiler. Rather it was used by the "unparser" when a user requested an ASCII representation of a program.


Users became upset when the exact keyword they specified was not present in the "unparsed" instance, even when the program was otherwise equivalent. I first stumbled across what I call the "passion of the keyword" around when a new member of our internal testing group issued a dead-in-the-water bug report against cfront itself. In cfront's original declaration of its internal type hierarchy, the root node and each derived subtype was declared with the keyword struct. simply inconsistent class node; struct node { The real issue, however, is not whether all declarations of a user-defined type must use a consistent keyword. Rather the issue is whether the use of the class or struct keyword makes any promise as to the internal declaration of the type.


That is, if use of the struct keyword enforces the C concept of a data abstraction, while use of the class keyword enforces the concept of an ADT, then, of course, failure to be consistent is an incorrect usage of the language. extern int foo; This set of declarations makes contrary storage claims on the object foo. However, as you've seen, use of either the struct or class keyword makes no such claims. The actual characteristics of the class are determined by the body of the declaration. Enforcing a consistent usage is simply a question of style. The second time I stubbed my implementation toe on this issue was during Release 3. Let's strike aside struct, I said, and be done with it. Honestly, I don't recall. However, I do recall changing the parser to accept both keywords. Thus are language dialects born! One might argue, then, that a great deal of confusion could be removed if the language chose to support only one of the two keywords.


It is impossible not to support struct if one wishes to support existing C code. And the language simply had to do that. Well, then was it necessary to introduce the additional keyword class? Really necessary? Imagine, for example, speaking of an abstract base struct or of the Zoo Animal struct hierarchy containing one or more virtual base structs. In the preceding discussion, I distinguished between use of the keyword struct and the philosophical concept of a struct declaration. One might claim that use of the keyword accompanied by the declaration of a public interface the philosophical underpinning of a class is like the use of slang or diminutives in public discourse. pc, string ; This may or may not translate well when placed within a class declaration that z specifies multiple access sections containing data, z derives from another class or is itself the object of derivation, or z defines one or more virtual functions.


The layout of data contained in multiple access sections, however, is left undefined. The presence of a virtual function also places the trick's viability in question. The best advice is not to do it. Chapter 3 discusses these layout issues in greater detail. This struct declaration serves to encapsulate that data and guarantees a compatible C storage layout. This guarantee, however, is maintained only under composition. Under inheritance, the compiler decides whether additional data members are inserted within the base struct subobject again, see Section 3. The abstract data type ADT model in which users of the abstraction are provided with a set of operations the public interface , while the implementation remains hidden.


The object-oriented OO model in which a collection of related types are encapsulated through an abstract base class providing a common interface. Mixed paradigm programs, however, hold a greater potential for surprise, particularly when the mixing is inadvertent. The definition and use of thing2 in the previous example is a well-behaved instance of the OO paradigm. The definition and use of thing1 falls outside the OO idiom; it reflects a well-behaved instance of the ADT paradigm. Whether the behavior of thing1 is good or bad depends on what the programmer intended. In this example, its behavior is very likely a surprise. In the OO paradigm, the programmer manipulates an unknown instance of a bounded but infinite set of types. The set of types is bounded by its inheritance hierarchy; in theory, however, there is no limit to the depth and breadth of that hierarchy.


In contrast, in the ADT paradigm the programmer manipulates an instance of a fixed, singular type that is completely defined at the point of compilation. Later in this section, I discuss why this behavior, although perhaps unexpected, is well behaved. px, for example, may address either an object of its own type or a type publicly derived from it not considering ill-behaved casts. One might say that they are not first-class polymorphic objects. The primary use of polymorphism is to effect type encapsulation through a shared interface usually defined within an abstract base class from which specific subtypes are derived. This shared interface is invoked through the virtual function mechanism that resolves which instance of a function to invoke based on the actual type of the object at each point during execution. rotate ; reference. In this example, they both invoke Z::rotate. The invocation through datum may or may not be invoked through the virtual mechanism; however, it will always invoke X::rotate.


This is what is called a "quality of compilation" issue: whether the invocation of a virtual function through datum circumvents or employs the virtual mechanism. Semantically, the results are equivalent. This is looked at in more detail in Section 4. The memory requirements to represent a class object in general are the following: z The accumulated size of its nonstatic data members z Plus any padding between members or on the aggregate boundary itself due to alignment constraints or simple efficiency z Plus any internally generated overhead to support the virtuals The memory requirement to represent a pointer, [2] however, is a fixed size regardless of the type it addresses. For example, given the following declaration of a ZooAnimal class: [2] Or to represent a reference; internally, a reference is generally implemented as a pointer and the object syntax transformed into the indirection required of a pointer.


I return to the layout of data members in Chapter 3. Layout of Object and Pointer of Independent Class The Type of a Pointer But how, then, does a pointer to a ZooAnimal differ from, say, a pointer to an integer or a pointer to a template Array instantiated with a String? So the difference between pointers to different types rests neither in the representation of the pointer nor in the values addresses the pointers may hold. The difference lies in the type of object being addressed. That is, the type of a pointer instructs the compiler as to how to interpret the memory found at a particular address and also just how much memory that interpretation should span: z An integer pointer addressing memory location on a bit machine spans the address space — z The ZooAnimal pointer, if we presume a conventional 8-byte String a 4-byte character pointer and an integer to hold the string length , spans the address space — That's right, we don't know.


So a cast in general is a kind of compiler directive. In most cases, it does not alter the actual address a pointer contains. Rather, it alters only the interpretation of the size and composition of the memory being addressed. Adding Polymorphism Now, let's define a Bear as a kind of ZooAnimal. protected: enum Dances { Both the pointer and reference require a single word of storage 4 bytes on a bit processor. The Bear object itself, however, requires 24 bytes the size of a ZooAnimal [16 bytes] plus the 8 bytes Bear introduces. A likely memory layout is pictured in Figure 1. Layout of Object and Pointer of Derived Class Okay, given that our Bear object is situated at memory location , what are the real differences between a Bear and ZooAnimal pointer?


The difference is that the address span of pb encompasses the entire Bear object, while the span of pz encompasses only the ZooAnimal subobject of Bear. The encapsulation of the type information is maintained not in pz but in the link between the object's vptr and the virtual table the vptr addresses see Section 4. rotate ; the instance of rotate invoked is the ZooAnimal instance and not that of Bear? Moreover, if memberwise initialization copies the values of one object to another, why is za's vptr not addressing Bear's virtual table?


The answer to the second question is that the compiler intercedes in the initialization and assignment of one class object with another. The compiler must ensure that if an object contains one or more vptrs, those vptr values are not initialized or changed by the source object. The answer to the first question is that za is not and can never be a Bear; it is and can never be anything but a ZooAnimal. Polymorphism, the potential to be of more than one type, is not physically possible in directly accessed objects. Paradoxically, direct object manipulation is not supported under OO programming. A pointer and a reference support polymorphism because they do not involve any type-dependent commitment of resources. Rather, all that is altered is the interpretation of the size and composition of the memory they address. Any attempt to alter the actual size of the object za, however, violates the contracted resource requirements of its definition.


Get a value-added service! Try out all the examples from this book at www. CodeSaw is a free online learning tool that allows you to experiment with live code from your book right in your browser. About the author Stanley B. Previously, he served as a Distinguished Consultant at the Jet Propulsion Laboratories JPL. After Bell Laboratories, Stan worked at Disney Feature Animation, originally as principal software engineer, then as software technical director on Fantasia Search Images Maps Play YouTube News Gmail Drive More Calendar Translate Books Shopping Blogger Finance Photos Videos Docs. Account Options Sign in. My library Help Advanced Book Search.



edu no longer supports Internet Explorer. To browse Academia. edu and the wider internet faster and more securely, please take a few seconds to upgrade your browser. Log in with Facebook Log in with Google. Remember me on this computer. Enter the email address you signed up with and we'll email you a reset link. Need an account? Click here to sign up. Download Free PDF. Continue Reading Download Free PDF. This book shows how your understanding the underlying implementation models can help you code more efficiently and with greater confidence. He then explains how the various implementation models arose, points out areas in which they are likely to evolve, and why they are what they are.


z Explains the basic implementation of the object-oriented features and the trade offs implicit in those features. z Examines the impact on performance in terms of program transformation. z Provides abundant program examples, diagrams, and performance measurements to relate object- oriented concepts to the underlying object model. Organization of This Book The Intended Audience A Note on Program Examples and Program Execution Acknowledgments References Chapter 1. Object Lessons Layout Costs for Adding Encapsulation Section 1. A Keyword Distinction Section 1. An Object Distinction Chapter 2. The Semantics of Constructors Section 2. Default Constructor Construction Section 2. Copy Constructor Construction Section 2. Program Transformation Semantics Section 2. Member Initialization List Chapter 3. The Semantics of Data Section 3. The Binding of a Data Member Section 3. Data Member Layout Section 3.


Access of a Data Member Section 3. Inheritance and the Data Member Section 3. Object Member Efficiency Section 3. Pointer to Data Members Chapter 4. The Semantics of Function Section 4. Varieties of Member Invocation Section 4. Virtual Member Functions Section 4. Pointer-to-Member Functions Section 4. Inline Functions Chapter 5. Semantics of Construction, Destruction, and Copy Presence of a Pure Virtual Destructor Presence of a Virtual Specification Presence of const within a Virtual Specification A Reconsidered Class Declaration Section 5. Object Construction without Inheritance Section 5. Object Construction under Inheritance Section 5. Object Copy Semantics Section 5. Object Efficiency Section 5.


Semantics of Destruction Chapter 6. Runtime Semantics Section 6. Object Construction and Destruction Section 6. Operators new and delete Section 6. Temporary Objects Chapter 7. On the Cusp of the Object Model Section 7. Templates Section 7. Exception Handling Section 7. Runtime Type Identification Section 7. Efficient, but Inflexible? Ru-Brd Ru-Brd Copyright The frontispiece art is an engraving Knight, Death and the Devil by Albrecht Dürer, — Courtesy, Museum of Fine Arts, Boston, Massachusetts. Gift of Mrs. Horatio Greenough Curtis in Memory of her Husband, Horatio Greenough Curtis. The photograph on the back cover is by David Remba. Extracts on pages — are from the Journal of C Language Translation, Vol.


Copyright , I. Levine, Trumansburg, New York. Reprinted by permission of the publisher. Senior Editor: Tom Stone Associate Editor: Debbie Lafferty Associate Production Supervisor: Patricia A. Oduor Copyeditor: Diane Freed Proofreader: Bunny Ames Art Editing Supervisor: Meredith Nightingale Senior Manufacturing Coordinator: Judith Y. Sullivan Library of Congress Cataloging-in-Publication Data Lippman, Stanley B. cm Includes bibliographical references and index. Object-oriented programming Computer science I. Title: C plus plus object models ZA CL58 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher.


Printed in the United States of America. It was during the Simplifier's design period that I conceived of and began working on this book. What was the Foundation project? It was an exciting project, both for the work we were doing and for the people doing the work: Bjarne, Andy Koenig, Rob Murray, Martin Carroll, Judy Ward, Steve Buroff, Peter Juhl, and myself. Barbara Moo was supervising the gang of us other than Bjarne and Andy. Barbara used to say that managing a software group was like herding a pride of cats.


Internally, we called it Grail, as in the quest for, etc. It seems a Bell Laboratories tradition to mock one's most serious intentions. Grail provided for a persistent, semantic-based representation of the program using an object-oriented hierarchy Rob Murray developed and named ALF. Within Grail, the traditional compiler was factored into separate executables. The parser built up the ALF representation. Each of the other components type checking, simplification, and code generation and any tools, such as a browser, operated on and possibly augmented a centrally stored ALF representation of the program. The Simplifier is the part of the compiler between type checking and code generation. Bjarne came up with the name Simplifier; it is a phase of the original cfront implementation. What does a Simplifier do between type checking and code generation? It transforms the internal program representation. There are three general flavors of transformations required by any object model component: 1.


Implementation-dependent transformations. These are implementation-specific aspects and vary across compilers. Under ALF, they involved the transformations of what we called "tentative" nodes. For example, when the parser sees the expression fct ; it doesn't know if this is a an invocation of a function represented or pointed to by fct or b the application of an overloaded call operator on a class object fct. By default, the expression is represented as a function call. The Simplifier rewrites and replaces the call subtree when case b applies. Language semantics transformations. Code and object model transformations. These include support for virtual functions, virtual base classes and inheritance in general, operators new and delete, arrays of class objects, local static class instances, and the static initialization of global objects with nonconstant expressions.


An implementation goal I aimed for in the Simplifier was to provide an Object Model hierarchy in which the object implementation was a virtual interface supporting multiple object models. These last two categories of transformations form the basis of this book. Does this mean this book is written for compiler writers? No, absolutely not.



Download Inside the C++ Object Model de Lippman Stanley PDF [ePub Mobi] Gratis,Account Options

Web · Inside the C++ Object Model focuses on the underlying mechanisms that support object-oriented programming within C++: constructor semantics, temporary Webebook/inside the c++ object blogger.com Go to file. Cannot retrieve contributors at this time. MB. Download WebINSIDE THE C++ OBJECT MODEL FREE DOWNLOAD Author: Stanley B. Lippman Number of Pages: pages Published Date: 13 May Publisher: Pearson Web downloads Views KB Size Report This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site WebDownload Inside the C++ Object Model PDF book author, online PDF book editor Inside the C++ Object Model. Download and stutter books online, ePub / PDF online / Audible WebDownload Original PDF This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, ... read more



s means load a single-precision floating-point value; s. The most dramatic impact on our program is the return of local by value on line The Standard permits the vptr to be placed anywhere within the object: at the beginning, at the end, or in between either of the three members. The assignment of the address of a second or subsequent base class, however, requires that that address be modified by the addition or subtraction in the case of a downcast of the size of the intervening base class subobject s. The members are assigned a slot in the order of their declarations.



Appreciation also goes to M. Foo::Foo ; } Again, note that the synthesized default constructor meets only the needs of the implementation, not the needs of the program. It should come from an understanding of the Object Model. All rights reserved. One could argue, shouldn't the invocation of a pure virtual destructor be suppressed by the compiler during the augmentation of the destructor of the derived class?

No comments:

Post a Comment

Pages

Blog Archive

Total Pageviews