home bbs files messages ]

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

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

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

   Message 241,244 of 243,242   
   Kaz Kylheku to All   
   Nice way of allocating flexible struct.   
   08 Oct 25 06:35:28   
   
   From: 643-408-1753@kylheku.com   
      
   Jonas Lund of https://whizzter.woorlic.org/ mentioned this   
   trick in a HackerNews comment:   
      
   Given:   
      
     struct S {   
       // ...   
       T A[];   
     };   
      
   Don't do this:   
      
     malloc(offsetof(S, A) + n * sizeof (T));   
      
   But rather this:   
      
     malloc(offsetof(S, A[n]));   
      
   It's easy to forget that the second argument of offsetof is a   
   designator, not simply a member name.   
      
   --   
   TXR Programming Language: http://nongnu.org/txr   
   Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal   
   Mastodon: @Kazinator@mstdn.ca   
      
   --- 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