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

  • SEARCH
  • Home
  • 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 8040439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:53:49+00:00 2026-06-05T03:53:49+00:00

I am working in a plain C (embedded project, little memory) and I have

  • 0

I am working in a plain C (embedded project, little memory) and I have a structure

typedef struct 
{
   int x;
   int y;
   int z;
   float angle;
   float angle1;
   float angle2;
} Kind1;

There are cases when I need all fields, and there are cases when I need x, y and angle only.

In C++ I would create a base class with these 3 fields, would inherit from it another class with additional 3 fields and would instantiate one or another per need. How can I emulate this behaviour in plain C?

I know that I can make something like

typedef struct 
{
   int x;
   int y;
   float angle;
} Kind1;

typedef struct
{ 
   Kind1 basedata;
   int z;
   float angle2;
   float angle3;
}  Kind2;

but then I cannot pass pointer to Kind2 where a pointer to Kind1 is requested.

I know that it is possible to typecast and offset the pointer, I just wonder if there is a better, safer way.

  • 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-06-05T03:53:51+00:00Added an answer on June 5, 2026 at 3:53 am

    I know that it is possible to typecast and offset the pointer

    Not necessarily:

    void foo(Kind1*);
    struct Kind2
    { 
       Kind1 basedata;
       int z;
       float angle2;
       float angle3;
    }
    
    //...
    Kind2 k;
    foo(&(k.basedata));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the project I'm currently working on, I don't have plain CLR objects to
I am currently working on a Java EE project. I have successfully developed a
I'm writing a plain C project. I'm using a Mac and I like working
I am working on a project for my computer security class and I have
I'm working on a little project, the aim being to generate a report from
In an app I'm working on, I have a plain style UITableView that can
So, I’m working on a plain-C (ANSI 9899:1999) project, and am trying to figure
I'm currently working on encryption/decryption of plain text files that are embedded in a
I am currently working on a web application where I have encountered a little
I have a working Rails 3 app service plain old HTML CRUD and I

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.