A Question On Inside the C++ Object Model

This is a discussion on A Question On Inside the C++ Object Model within the C++ Programming forums, part of the General Programming Boards category; I'm reading Inside the C++ Object Model , and I'm somewhat confused as described below: At the end of "1.2 ...

  1. #1
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    212

    A Question On Inside the C++ Object Model

    I'm reading Inside the C++ Object Model, and I'm somewhat confused as described below:

    At the end of "1.2 A Keyword Distinction", the author pointed out that "This idiom is no longer recommended, however, because of changes to the class inheritance layout in some compilers":

    PHP Code:
            struct C_point { ... }; 
            class 
    Point : public C_point { ... }; 

            
    extern void draw_linePointPoint ); 
            
    extern "C" void draw_rect C_pointC_Point ); 

            
    draw_linePoint0), Point100100 )); 
            
    draw_rectPoint0), Point100100 )); 
    I guess the author meant that "some implementations began placing the vptr at the start of the class object... loss in C language interoperability" (from 3.4 Inheritance and the Data Member).

    In my opinion, at the invocation of draw_rect(Point(0, 0), Point(100, 100)), the compiler knows draw_rect needs objects of type C_point, thus the compiler could push only the C_point part of the Point object into the stack. So I think the call to draw_rect with objects of type Point should be OK.

    Would somebody please kindly tell me why and in what kind of situation will "draw_rect(Point(0, 0), Point(100, 100))" fail?

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,789
    You should beware that structs are essentially classes, as well. They can contain functions, virtual functions and inheritance. In such cases, you cannot safely pass them to a C function.
    I believe, but don't quote me on this, that so long as C_point is a POD, it should work fine. The object would be sliced, but work.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array class object question
    By ExDHaos in forum C++ Programming
    Replies: 3
    Last Post: 05-16-2009, 11:23 AM
  2. synchronization object choosing
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 04:33 AM
  3. Question about cout an stack object?
    By joenching in forum C++ Programming
    Replies: 8
    Last Post: 05-08-2005, 10:10 PM
  4. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  5. Help with file reading/dynamic memory allocation
    By Quasar in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2004, 03:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21