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 9180599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:05:59+00:00 2026-06-17T18:05:59+00:00

I’m trying to come up with a way to declare several data structures that

  • 0

I’m trying to come up with a way to declare several data structures that
are arrays of structures, where each subsequent array uses part of an earlier one.
way that minimizes duplication. That way each element is declared only once.

So conceptually, imagine these four arrays, where a given element number that
appears in both arrays is meant to represent the actual same thing, not just
another one with the same value.

some_type group_A[] = {
    elt0, elt1, elt2, elt3, NULL
};

some_type group_B[] = {
    elt0, elt1, elt2, elt3,  // those are all A's
    elt4, elt5, NULL         // these are new to B
};

some_type group_C[] = {
    elt0, elt1, elt2, elt3,  // those are all A's
    elt6, elt7, elt8, NULL   // these are new to C
};

some_type group_D[] = {
    elt0, elt1, elt2, elt3, elt4, elt5, // those are all B's
    elt9, elt10, elt11, NULL            // these are new to D
};

You can assume that some_type is already a typedef for some kind of structure.

What I would like to do is eliminate the redundant declarations, because they seem untidy in general and because they open you up to update incoherency. Here is the more compact representation, where an entry in a group can be a normal element or it can be a reference to another array of such elements.

(You would be right to infer by the NULL ponter at the end that each array declaration that each element is really a pointer to a structure of the same type.)

some_type group_A[] = {
    elt0, elt1, elt2, elt3, NULL
};

some_type group_B[] = {
    Group_A, elt4, elt5, NULL
};

some_type group_C[] = {
    Group_A, elt6, elt7, elt8, NULL
};

some_type group_D[] = {
    Group_B, elt9, elt10, elt11, NULL
};

In other words, I want a way to declare that Group_B and Group_C both begin with everything in Group_A, but then have their elements after that, and that Group_D contains everything in Group_B (itself in turn including everything in Group_A) and then adding its own elements.

I want this to be declarative, just a bunch of array data declarations, that happens at compile-time not a run-time bunch of data-structure-building code.

This would be forbidden from recursing, at least in practice and at run-time.

Is there a nice, declarative, looks-like-an-array implementation of this, or must I restort to some more complicated dynamic data structure implementation that isn’t all fixed at compile-time the way I prefer?

My hunch is that a tagged union of some sort may be the only way to go.

struct pointer_or_doublepointer {
    int  which_kind;   // 0 == .element is valid; 1 == .table is valid
    union {
        real_type *  element; // valid only when which_kind == 0
        real_type ** table;   // valid only when which_kind == 1
    };
}

And then I would just make some_type a typedef for pointer_or_doublepointer.

Is this really the best way to set something like this up, or is there some
other better and more straightforward solution that comes to mind? Again, remember this is all supposed to be done via data declarations, not via code.

This is to be in pure C, not in C++ or some other variant.

  • 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-17T18:06:00+00:00Added an answer on June 17, 2026 at 6:06 pm

    Since you say that a reference to other arrays will only appear at the beginning, a simple way to represent this is to hold this reference separately from the rest of the elements:

    struct ElementList {
        struct ElementList *prefix; //Reference to elements of another array, or NULL
        some_type *elements;        //additional elements
    };
    

    This is more limited than the union solution, but probably easier to use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am confused How to use looping for Json response Array in another Array.
I've got a string that has curly quotes in it. I'd like to replace

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.