Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 421045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:56:41+00:00 2026-05-12T18:56:41+00:00

I read that early C++ compilers actually translated the C++ code to C and

  • 0

I read that early C++ “compilers” actually translated the C++ code to C and used a C compiler on the backend, and that made me wonder. I’ve got enough technical knowledge to wrap my head around most of how that would work, but I can’t figure out how to do class inheritance without having language support for it.

Specifically, how do you define a class with a few fields, then a bunch of subclasses that inherit from it and each add their own new fields, and be able to pass them around interchangeably as function arguments? And especially how can you do it when C++ allows you to allocate objects on the stack, so you might not even have pointers to hide behind?

NOTE: The first couple answers I got were about polymorphism. I know all about polymorphism and virtual methods. I’ve even given a conference presentation once about the low-level details of how the virtual method table in Delphi works. What I’m wondering about is class inheritance and fields, not polymorphism.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:56:42+00:00Added an answer on May 12, 2026 at 6:56 pm

    In C anyway you an do it the way cfront used to do it in the early days of C++ when the C++ code was translated into C. But you need to be quite disciplined and do all the grunt work manually.

    Your ‘classes’ have to be initialized using a function that performs the constructor’s work. this will include initializing a pointer to a table of polymorphic function pointers for the virtual functions. Virtual function calls have to be made through the vtbl function pointer (which will point to a structure of function pointers – one for each virtual function).

    The virtual function structure for each derived calss needs to be a super-set of the one for the base class.

    Some of the mechanics of this might be hidden/aided using macros.

    Miro Samek’s first edition of “Practical Statecharts in C/C++” has an Appendix A – “C+ – Object Oriented Programming in C” that has such macros. It looks like this was dropped from the second edition. Probably because it’s more trouble than it’s worth. Just use C++ if you want to do this…

    You should also read Lippman’s “Inside the C++ Object Model” which goes into gory details about how C++ works behind the scenes, often with snippets of how things might work in C.


    I think I see what you’re after. Maybe.

    How can something like this work:

    typedef 
    struct foo {
        int a;
    } foo;
    
    void doSomething( foo f);   // note: f is passed by value
    
    typedef
    struct bar {
        foo base;
        int b;
    } bar;
    
    
    int main() {
        bar b = { { 1 }, 2};
    
        doSomething( b);    // how can the compiler know to 'slice' b
                            //  down to a foo?
    
        return 0;
    }
    

    Well you can’t do that as simply as that without language support – you’d need to do some things manually (that’s what it means to not have language support):

        doSomething( b.base);       // this works
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 215k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The following usually works: Context.Refresh(RefreshMode.StoreWins, _ Context.ObjectStateManager.GetObjectStateEntries()) It sometimes causes… May 12, 2026 at 10:53 pm
  • Editorial Team
    Editorial Team added an answer My guess is that value is 8. :-) Are you… May 12, 2026 at 10:53 pm
  • Editorial Team
    Editorial Team added an answer I wrote up an answer to another question about the… May 12, 2026 at 10:53 pm

Related Questions

Even 2 decades ago, it was possible to call code written in one language
I know that you can use a dummy int parameter on operator++ and operator--
I read that early builds of Chrome supported ActiveX, but was later restricted to
I am in early beginning of learning and deploying Win App using C#, Now

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.