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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:44:39+00:00 2026-05-25T21:44:39+00:00

I’m working on some embedded software where there is some static information about products.

  • 0

I’m working on some embedded software where there is some static information about “products”. Since the information for a certain product never changes during execution I would like to initialize these data structures at compile time to save some space on the stack/heap.

I made a Product class for the data, intending to make a huge array of all the products in the system and then do lookups in this structure, but I haven’t figured out quite how to get it working. The arrays are giving me loads of trouble. Some psuedo code:

class Product {
    int m_price;
    int m_availability[]; // invalid, need to set a size
    ... etc

    // Constructor grabbing values for all members
    Product(int p, int a[], ...);
}

static const Product products[] = 
{
    Product(99, {52,30,63, 49}, ...), // invalid syntax
    ...                    
}                     

Is there a way to making something like this work? The only thing I can think of would be to organize by attribute and skip the whole Product object. I feel that would make the whole thing harder to understand and maintain though.

Does anyone have any suggestions on how I might best organize this kind of data?

Thank you.

  • 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-25T21:44:40+00:00Added an answer on May 25, 2026 at 9:44 pm

    An old school C style static array of structs sounds like a perfect match to your requirements. Initializes at compile time, zero runtime overhead, no use of stack or heap. It’s not a co-incidence that C is still a major player in the embedded world.

    So (one recipe – plenty of scope to change the details of this);

    // in .h file
        class Product {
        public: // putting this first means the class is really a struct
            int m_price;
            int m_availability[4]; 
            //.... (more)
        };
        extern const Product product_array[];
        extern const int     product_array_nbr;
    
    // in .cpp file
        const Product product_array[] =
        {
            {
                 23,
                 {56,1,2,4},
                 //....(more)
            },
            {
                 24,
                 {65,1,2,4},
                 //....(more)
            },
            //....(more)
        };
    
        const int product_array_nbr = sizeof(product_array)/sizeof(product_array[0]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have some data like this: 1 2 3 4 5 9 2 6

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.