Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #30433

Re: Using C preproc to uniquely identify structure members

From Hans-Bernhard Bröker <HBBroeker@t-online.de>
Newsgroups comp.arch.embedded
Subject Re: Using C preproc to uniquely identify structure members
Date 2021-04-10 23:16 +0200
Message-ID <ideispFm46eU1@mid.dfncis.de> (permalink)
References <s4soil$1e7o$1@gioia.aioe.org>

Show all headers | View raw


Am 10.04.2021 um 19:51 schrieb John Speth:
> I could use some advice for a problem that I've had on my mind for 
> years. I'm looking for a black box function that will examine a memory 
> block of a known structure and output a list of IDs that point to any 
> members that have changed.

The key flaw in that plan, as executed so far, is that you're trying to 
use a native C struct for this job.  Arbitrary data of varying amount 
and composition doesn't live comfortably in such a rigidly structured 
format.  Among others, forget about ever loading a piece of memory 
stored by a programming referring to one definition of that struct and 
having it interpreted sensibly by a program referring to a changed 
definition.  C structs are not at all meant for such work.

This is a job for a low-level type of database, or at the very least 
something like a tagged record-based data file.

> There is such a large number of members that my quest is to 
> automate as much as possible the ID and comparison operations. 

Automate what: the work of doing the actual comparison, or the work of 
creating/updating the code that does the comparison?

> Not 
> automating would require the programmer to redo the comparison 

I don't see a re-do, just an update to the existing comparison.

> #define    MEMBER(t,v) t v; size_t size_ ## v; size_t id_ ## v
> 
> typedef struct
> {
>    MEMBER(int,i);
>    MEMBER(char,c);
>    MEMBER(float,f);
> } STRUCT;

This design also violates an important principle: do not mix constant 
and variable data in the same structure.  This is even more important in 
smallish, bare-metal embedded work, where you want the constants to 
actually be in (flash) PROM, not waste space in RAM.

Worse than that, they wouldn't even contribute to the solution of the 
actual problem.  If these data remain strictly inside a realm of 
executable code using the exact same definition of that struct (on 
binary compatible platforms), you don't need the extra fields for 
anything.  If they can cross the boundary of that realm, having those 
elements doesn't help with the actual problem --- you then need a proper 
interface specification, which will _not_ be a C struct definition, for 
the transfer of those data, and serialization/deserialization functions 
to handle the translation between internal and external formats.

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Using C preproc to uniquely identify structure members John Speth <johnspeth@yahoo.com> - 2021-04-10 10:51 -0700
  Re: Using C preproc to uniquely identify structure members Don Y <blockedofcourse@foo.invalid> - 2021-04-10 13:19 -0700
  Re: Using C preproc to uniquely identify structure members Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2021-04-10 23:16 +0200
  Re: Using C preproc to uniquely identify structure members George Neuner <gneuner2@comcast.net> - 2021-04-10 18:12 -0400
    Re: Using C preproc to uniquely identify structure members Don Y <blockedofcourse@foo.invalid> - 2021-04-10 18:20 -0700
      Re: Using C preproc to uniquely identify structure members George Neuner <gneuner2@comcast.net> - 2021-04-12 13:06 -0400
        Re: Using C preproc to uniquely identify structure members Don Y <blockedofcourse@foo.invalid> - 2021-04-12 11:13 -0700
          Re: Using C preproc to uniquely identify structure members George Neuner <gneuner2@comcast.net> - 2021-04-12 21:51 -0400
            Re: Using C preproc to uniquely identify structure members Don Y <blockedofcourse@foo.invalid> - 2021-04-12 20:49 -0700
          Re: Using C preproc to uniquely identify structure members David Brown <david.brown@hesbynett.no> - 2021-04-13 13:07 +0200
  Re: Using C preproc to uniquely identify structure members John Speth <johnspeth@yahoo.com> - 2021-04-11 07:42 -0700
    Re: Using C preproc to uniquely identify structure members Don Y <blockedofcourse@foo.invalid> - 2021-04-11 12:56 -0700

csiph-web