XPost: alt.folklore.computers   
   From: johnl@taugh.com   
      
   It appears that c186282 said:   
   >On 1/2/26 13:26, John Levine wrote:   
   >> No, the C Standard says:   
   >>   
   >> Within a structure object, the non-bit-field members and the units in   
   which bit-fields   
   >> reside have addresses that increase in the order in which they are   
   declared.   
   >>   
   >> There can be bits of padding to get fields aligned as needed, but no   
   reordering.   
   >> It is pretty common to use structure declarations with common fields at the   
   >> front to do varriant records.   
   >   
   > Hmmm ... with arrays of simple types you can   
   > advance the pointer by 'x' and get the 'x'-th   
   > element. In theory you can manually peek 'x'   
   > (times type) bytes ahead in memory too.   
   >   
   > Is that not for-sure correct with variant records ?   
      
   C doesn't have variant records, but you can fake them with structures with   
   common initial fields. The different structures can be different sizes   
   so the usual approach is to malloc() them one at a time and use a pointer to   
   it.   
      
   As bonus confusion, C allows the last field in a structure to be an array of   
   unspecified size, e.g.   
      
   struct countedstring {   
    int length;   
    char data[];   
   };   
      
   Then for a string of innitialized from srcstring you'd say something like:   
      
    struct countedstring *p = malloc(sizeof(struct countedstring) +   
   strlen(srcstring));   
    p->length = nchars;   
    memcpy((void *)p->data, (void *)srcstring, strlen(srcstring));   
      
      
      
      
   --   
   Regards,   
   John Levine, johnl@taugh.com, Primary Perpetrator of "The Internet for   
   Dummies",   
   Please consider the environment before reading this e-mail. https://jl.ly   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|