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,250 of 243,242   
   Richard Tobin to pozzugno@gmail.com   
   Re: Nice way of allocating flexible stru   
   08 Oct 25 12:01:03   
   
   From: richard@cogsci.ed.ac.uk   
      
   In article <10c52nj$pnn0$1@dont-email.me>, pozz   wrote:   
      
   >struct S {   
   >   unsigned int size;   
   >   unsigned char mode;   
   >   unsigned char array[];   
   >}   
      
   >And another question. Suppose I need an array of struct S. All elements   
   >have 7-bytes array[] member. How to allocate this array and access each   
   >element?   
      
   To get the size, round up offsetof(struct S, array[7]) to a multiple   
   of _Alignof(struct S).   
      
   To access an element, I think you will have to determine its offset   
   and cast a char pointer.   
      
   -- Richard   
      
   --- 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