473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C++ Object Model

Which sections of the 2003 standard should I study to understand the
object model? I am looking to find information similar to that in
Stanley B. Lippman's book, "Inside the C++ Object Model"

Mar 12 '06 #1
8 3476

al*****@gmail.com skrev:
Which sections of the 2003 standard should I study to understand the
object model? I am looking to find information similar to that in
Stanley B. Lippman's book, "Inside the C++ Object Model"


If I understand you correctly, no part of the standard will be
relevant. The standard mandates almost nothing w.r.t. the physical
layout of objects (the most important exception being that a
std::vector must be implemented as one contigeous chunk of memory).
One thing that could tell you about a possible implementation of C++ is
the C++ performance report. Google for it.

/Peter

Mar 12 '06 #2
Me
al*****@gmail.com wrote:
Which sections of the 2003 standard should I study to understand the
object model? I am looking to find information similar to that in
Stanley B. Lippman's book, "Inside the C++ Object Model"


I'm not really sure what you mean by object model but if it's anything
like the book, these are the things you need to look for in the
standard:

static_cast
dynamic_cast
typeid
virtual functions
virtual members
member function pointers
member data pointers

and how

multiple inheritence
virtual inheritence
private inheritence

interacts with the above

(I believe this is a complete list). The C++ standard just says the
layout of non-POD classes are implementation defined, so if you're
looking for any hints by the standard, you're out of luck. But you
definitely should be aware that C++ allows diamond style inheritence as
pictured in this iostreams chart:
http://www.cplusplus.com/ref/iostream/

Mar 12 '06 #3
peter koch wrote:
al*****@gmail.com skrev:
Which sections of the 2003 standard should I study to understand the
object model? I am looking to find information similar to that in
Stanley B. Lippman's book, "Inside the C++ Object Model"


If I understand you correctly, no part of the standard will be
relevant. The standard mandates almost nothing w.r.t. the physical
layout of objects (the most important exception being that a
std::vector must be implemented as one contigeous chunk of memory).
One thing that could tell you about a possible implementation of C++ is
the C++ performance report. Google for it.

/Peter


I recently had an interview for a C++ programmer position and the
interviewer asked me questions like:

where does the virtual table reside? (my answer: in memory)
why don't we make all destructors virtual? (my answer: because they
will cost memory due to vtable and some classes are not designed to be
base classes)
If we add a virtual function to a class will we see an increase in
class size? (i said yes)
While size of class grow at constant rate with the addition of each
virtual function? (i said not sure)

He then paused and gave me some advice on which books to read, saying
that I must read "Inside the C++ Object Model". He also said that I
can't be a good C++ programmer without being a good C programmer. It is
disappointing because I answered each question to the best of my
ability. There were some algorithm problems as well but he criticized
me most for knowledge of C++. So essentially there is no set standard
for how objects should be represented internally?

Mar 12 '06 #4
Me wrote:
al*****@gmail.com wrote:
Which sections of the 2003 standard should I study to understand the
object model? I am looking to find information similar to that in
Stanley B. Lippman's book, "Inside the C++ Object Model"


I'm not really sure what you mean by object model but if it's anything
like the book, these are the things you need to look for in the
standard:

static_cast
dynamic_cast
typeid
virtual functions
virtual members
member function pointers
member data pointers

and how

multiple inheritence
virtual inheritence
private inheritence

interacts with the above

(I believe this is a complete list). The C++ standard just says the
layout of non-POD classes are implementation defined, so if you're
looking for any hints by the standard, you're out of luck. But you
definitely should be aware that C++ allows diamond style inheritence as
pictured in this iostreams chart:
http://www.cplusplus.com/ref/iostream/


Thank you, I'll read these and get back with any questions.

Mar 12 '06 #5
> I recently had an interview for a C++ programmer position and the
interviewer asked me questions like:

where does the virtual table reside? (my answer: in memory)
Correct. Static memory most likely.
why don't we make all destructors virtual? (my answer: because they
will cost memory due to vtable and some classes are not designed to be
base classes)
Correct.
If we add a virtual function to a class will we see an increase in
class size? (i said yes)
You have to ask him back what he means by "class size". If what he
refers to is the size of memory allocated for an object of such a class.

If he agrees you have to ask him whether there is already a virtual
function in such a class. If the answer is yes then there is unlikely a
change in "size"; otherwise an increase in the size is possible.
While size of class grow at constant rate with the addition of each
virtual function? (i said not sure)
Again you need a better definition for "class size". If that means the
size of the static memory needed to support such a class (such that
reserved for class information especially concerning the virtual
functions) then the answer is yes. If the term means what I assumed in
the previous paragraph, it is unlikely. Again this is highly
implementation dependent.
He then paused and gave me some advice on which books to read, saying
that I must read "Inside the C++ Object Model". He also said that I
can't be a good C++ programmer without being a good C programmer. It is
disappointing because I answered each question to the best of my
ability. There were some algorithm problems as well but he criticized
me most for knowledge of C++. So essentially there is no set standard
for how objects should be represented internally?


If that's his reason to dismiss you then you may be better off being
dismissed. The interviewer as described seems to have a screw loose in
his head.

Regards,
Ben
Mar 13 '06 #6
Me
al*****@gmail.com wrote:
Which sections of the 2003 standard should I study to understand the
object model? I am looking to find information similar to that in
Stanley B. Lippman's book, "Inside the C++ Object Model"

I recently had an interview for a C++ programmer position and the
interviewer asked me questions like:

where does the virtual table reside? (my answer: in memory)


This question assumes the compiler implements virtual functions as an
array of function pointers. The implementations listed in Lippman's
book (from memory and it's been a long while since I last read it) turn
the following:

class foo {
virtual void fn();
data d;
};

into one of (ignoring std::type_info):

// table inlined at the beginning
struct foo {
void (*fn)(foo*);
data d;
};

// table inlined at the end
struct foo {
data d;
void (*fn)(foo*);
};
struct foo_vtbl {
void (*fn)(foo*);
};

// vtable at beginning
struct foo {
const foo_vtbl *vtbl;
data d;
};

// vtable at end
struct foo {
data d;
const foo_vtbl *vtbl;
};

There are tons of other possible choices. One possibility is to keep
track of all RTTI objects in a giant global table and do a lookup based
on the address and then call the desired function based on a switch
statement. This has the advantage of requiring no storage inside the
class at all.
If we add a virtual function to a class will we see an increase in
class size? (i said yes)
While size of class grow at constant rate with the addition of each
virtual function? (i said not sure)
These two questions support my assumption about those 4 implementations
above. You can see that if we inline the table, the class size
increases, but if we use a vtable, the class size stays constant.

For multiple/virtual inheritance with virtual data members this gets
much more complicated and it really depends on how the implementation
ties all the things required by the C++ standard together to see if
adding a virtual function in some base class increases the size.
He then paused and gave me some advice on which books to read, saying
that I must read "Inside the C++ Object Model". He also said that I
can't be a good C++ programmer without being a good C programmer.
This guy sounds like one of those people that gets really familiar with
how their compiler implements things and then makes all sorts of
non-standard conforming/portable assumptions instead of what the
standard actually guarantees. (I'd recommend getting the book though, I
used it to learn C++ but it definitely shouldn't be used as a
substitute for the C++ standard)
It is disappointing because I answered each question to the best of my
ability. There were some algorithm problems as well but he criticized
me most for knowledge of C++. So essentially there is no set standard
for how objects should be represented internally?


A C++ implementation may be required to follow some ABI for backwards
compatibility/interoperability reasons, but as far as the C++ standard
is concerned, the answer is no and the examples given in the book were
pretty much cfront centric and designed to be easily ported. Non-cfront
compilers have the advantage of knowing the machine model and can do
all sorts of evil tricks like using thunks.

Mar 13 '06 #7

al*****@gmail.com skrev:
peter koch wrote: [snip]
I recently had an interview for a C++ programmer position and the
interviewer asked me questions like:

where does the virtual table reside? (my answer: in memory)
why don't we make all destructors virtual? (my answer: because they
will cost memory due to vtable and some classes are not designed to be
base classes)
If we add a virtual function to a class will we see an increase in
class size? (i said yes)
While size of class grow at constant rate with the addition of each
virtual function? (i said not sure)

He then paused and gave me some advice on which books to read, saying
that I must read "Inside the C++ Object Model". He also said that I
can't be a good C++ programmer without being a good C programmer. It is
disappointing because I answered each question to the best of my
ability. There were some algorithm problems as well but he criticized
me most for knowledge of C++. So essentially there is no set standard
for how objects should be represented internally?


Nope - there is no standard layout of objects in C++. It is up to the
implementers of the particular compiler to find the smartest way to
store their data.
Apart from this, I really am not sure that I agree with your
interviewer.... knowledge of C is okay, but if it makes you program as
if you were programming in C, you would have been better off with no
knowledge of C. Still, being aware of what goes on "beneath" the C++
layer is a huge advantage when optimising and debugging programs.

Kind regards
Peter

Mar 13 '06 #8
Hi all,
I also got a lot of infor on this. But as every body has told it's not
true that C knowledge is required for the C++. I know people starting
from C++ and with no knowledge of C. Well it's a thinking that C++ is a
different language although it started as a superset of C. Well
currently i am trying to implement a subset of C++(As an assignment). I
think i should make it so that people can see what internally happens.
Please provide me comment on how to make it? Like how to design it so
that people can easily understand it. and whicl all things to refer for
it.
Tahnks

Mar 13 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. ...
4
by: Davíð Þórisson | last post by:
Hi, when I was programmin ASP/JScript I had a very nice utilitiy which I got from MSDN (Script56.CHM). It's simply a help file but containing object orientiated documentation of all scripting...
15
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for...
5
by: Seok Bee | last post by:
Hi All, I have a webform with a button to add record into the database. When the button is being clicked, the program will assign initial value controls in a detailsview control. When the first...
12
by: Doug | last post by:
Hi, I learned a little about the model view presenter pattern at a conference this last week and am experimenting with it. It's working pretty well but I have a question. I am trying to use...
2
by: oh.i.love.spam | last post by:
This is just an example... I don't have the access/ability to upload the actual code. Here is the meat in the XML that is returned from the $client- <VesselConfigurations...
0
by: =?Utf-8?B?SmVhbi1GcmFuY29pcyBCcmV0b24=?= | last post by:
"siddharthkhare@hotmail.com" wrote: The context is important in this kind of design concern : I assume there's a lot of user and that application will evolve to add richer functionality. My...
3
by: H. S. Lahman | last post by:
Responding to siddharthkhare... Ignore Topmind and frebe. They are anti-OO P/R guys. Let's not confuse things with specific 3GL syntax. At the OOA/D level the model looks like: | 1
23
by: tonytech08 | last post by:
What I like about the C++ object model: that the data portion of the class IS the object (dereferencing an object gets you the data of a POD object). What I don't like about the C++ object...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.