Hacker News new | past | comments | ask | show | jobs | submit login

That's related to something I would like which is to be able to set the number of elements in an incomplete struct.

   struct foo
   {
     size_t elements;
     int data[];
   };

   foo foo123 = {.elements = array_size(data), .data = {1, 2, 3}};
or struct str { size_t sz; char str[]; };

   str s123 = {.sz = strlen(.str), .str = "123"};





Clang and GCC just got the [[counted_by()]] attribute to help protect such structs in the kernel. But yes, native syntax for this would be nice.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: