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,246 of 243,242    |
|    Bonita Montero to All    |
|    Re: Nice way of allocating flexible stru    |
|    08 Oct 25 11:09:27    |
   
   From: Bonita.Montero@gmail.com   
      
   Am 08.10.2025 um 08:35 schrieb Kaz Kylheku:   
   > 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.   
   >   
      
   In a real language:   
      
   #include
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca