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,267 of 243,242   
   Chris M. Thomasson to Chris M. Thomasson   
   Re: Nice way of allocating flexible stru   
   08 Oct 25 13:36:13   
   
   From: chris.m.thomasson.1@gmail.com   
      
   On 10/8/2025 1:35 PM, Chris M. Thomasson wrote:   
   > On 10/7/2025 11:35 PM, Kaz Kylheku wrote:   
   >> 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.   
   >>   
   >   
   > For some god damn reason its raising memories of an older region   
   > allocator I mocked up in C:   
   >   
   > Still on pastebin. funny:   
   >   
   > https://groups.google.com/g/comp.lang.c/c/H_p2Ki5JhYU/m/rlSzqJsxCQAJ   
   >   
   > https://pastebin.com/raw/f37a23918   
   > (no ads, raw text)   
      
   Strange. For mock up alignment:   
      
   #define RALLOC_ALIGN_OF(mp_type) \   
      offsetof( \   
        struct { \   
          char pad_RALLOC_ALIGN_OF; \   
          mp_type type_RALLOC_ALIGN_OF; \   
        }, \   
        type_RALLOC_ALIGN_OF \   
      )   
      
   ^)   
      
   --- 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