is it possible to use alloca inside compound statement? Example:
typedef struct
{
size_t len;
char* data;
} string_t;
#define str_to_cstr(str) \
({ \
char* v = alloca(str.len + 1); \
v[len] = 0; \
memcpy(v, str.data, str.len); \
})
// ... and somewhere in deep space
int main()
{
string_t s = {4, "test"};
printf("%s\n", str_to_cstr(s));
return 0;
}
From my experience it works well, but I am not sure it is safe. BTW, it compiled with gcc 4.8.4