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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:51:44+00:00 2026-06-18T01:51:44+00:00

I have a lot of configuration data in EEPROM (4KB) which I read out

  • 0

I have a lot of configuration data in EEPROM (4KB) which I read out in packed structures. Throughout my firmware I need to read/change these values very frequently, and performance of packed structures is not optimal, so I have a second struct which is exactly the same, only not packed. I have to copy each value one by one from the packed struct to the unpacked one, which is error-prone, because when I add a value to the packed structure I also have to remember to add it to the copy-function.

Is there a smarter way to do this?

  • 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-18T01:51:45+00:00Added an answer on June 18, 2026 at 1:51 am

    This is the over-smart method of doing this, using the precompiler:

    mydata-fields.h

    FIELD(int, one)
    FIELD(char, two)
    FIELD(long, three)
    

    mydata.h

    #define FIELD(t, n) t n;
    struct MyData
    {
    #include "mydata-fields.h"
    };
    struct __attribute__((packed)) MyDataPacked /*or whatever your compiler needs */
    {
    #include "mydata-fields.h"
    };
    #undef FIELD
    
    #define FIELD(t, n) a->n = b->n;
    static inline void Unpack(MyData *a, MyDataPacked *b)
    {
    #include "mydata-fields.h"
    }
    static inline void Pack(MyDataPacked *a, MyData *b)
    {
    #include "mydata-fields.h"
    }
    #undef FIELD
    

    UPDATE: With a bit of imagination you can even write a generic packed.h that receives the names of the struct and the fields file as parameters:

    extract of packed.h

    /* ... */
    struct UNPACKED
    {
    #include FIELDS_H
    };
    /* and so on... */
    

    And then simply in the real file:

    mydata.h

    #define UNPACKED MyData
    #define PACKED MyDataPacked
    #define FIELDS_H "mydata-fields.h"
    #include "packed.h"
    #undef FIELDS_H
    #undef PACKED
    #undef UNPACKED
    

    This will be useful if you have a lot of packed/unpacked structures and want to avoid some typing.

    A not so evil solution would be to write a script (in Python!) that generates the code from the fields specification in some input text file.

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

Sidebar

Related Questions

We have an application that requires loading A LOT of configuration data at startup.
I've got a program where a lot of classes have really complicated configuration requirements.
I have lot of code in my Tornado app which looks like this: @tornado.web.asynchronous
At the moment, I have lot's of Java which does all kind of nifty
I am creating Excel file download using NOPI libraries. I have lot of data
I am trying to build a data mart. I have lot of dimensions, and
I have a configuration class in my objective-c app which reads a PLIST file
I have some SerialPort code that constantly needs to read data from a serial
I have a rails app that needs a lot of initial data. This data
I have an aggregate root called Configuration which represent's all the options configured for

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.