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,304 of 135,536   
   Chris Ahlstrom to John Levine   
   Re: C structure portability, naughty Pyt   
   03 Jan 26 07:03:38   
   
   XPost: alt.folklore.computers   
   From: OFeem1987@teleworm.us   
      
   John Levine wrote this post by blinking in Morse code:   
      
   > 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.   
      
   I once created an audio playback app with class hierarchies in C, rather   
   than C++. It was an interesting experiment, and it worked. But   
   that's the last time I tried that.   
      
   --   
   Try not to have a good time ... This is supposed to be educational.   
   		-- Charles Schulz   
      
   --- 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