C: Recommended style for dynamically sized structs

后端 未结 4 1758
轻奢々
轻奢々 2020-12-31 14:41

I need to transfer packets through the internet whose length should be dynamic.

struct packet
{
  int id;
  int filename_len;
  char filename[];
};
         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-31 15:03

    Indeed zero-length arrays are not part of the standard. But what you have in your code snippet is a flexible array which is part of the ISO C99 standard. If it is possible for you to use C99, I'd use a flexible array, if not jesup's suggestion is probably the best.

提交回复
热议问题