Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can declare flexible array member strings with literals like this:

#define DECLARE_STRING(variable_name, string) struct{size_t allocated; size_t used; char string[sizeof(c_string)];} variable_name ## internal = {.allocated = sizeof(c_string) - 1, .used = sizeof(c_string) - 1, .string = c_string}; MyString *variable_name = &variable_name ## internal

Its a lot of C99 magic, so it may not be what you want but it is possible.



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

Search: