home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.linux.misc      Linux-specific topics not covered by oth      135,536 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 134,290 of 135,536   
   John Levine to All   
   Re: C structure portability, naughty Pyt   
   03 Jan 26 02:47:23   
   
   XPost: alt.folklore.computers   
   From: johnl@taugh.com   
      
   According to rbowman  :   
   >On Fri, 2 Jan 2026 20:32:53 -0000 (UTC), John Levine wrote:   
   >   
   >> 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.   
   >   
   >Another approach is to have a struct containing union of structs with a   
   >flag in the top level struct indicating which child struct to use in the   
   >union. The structs in the union can also have unions so you can build a   
   >real octopus.   
      
   That works but the union is the size of the largest struct so it can waste   
   a lot of space compared to allocating each struct's actual size.  I realize   
   this doesn't work for arrays of structs or unions, but it works fine for   
   arrays of pointers to them.   
      
   --   
   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)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca