Getting some trouble with a function in C that basically creates and allocates a temporary array with help of the length of the name parameter + extension length.
int my_func(char *name)
{
char *extension = ".db";
size_t tmp_size = strlen(name) + strlen(extension);
char tmp_name[tmp_size];
return 0;
}
This does not however seem to work on MSVC but works fine on Clang or GCC. Any idea why I get these errors:
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2133: 'tmp_name': unknown size
When I use the debugger in Clang on macOS I see that it allocates and work fine. Why not for MSVC?
MAX_PATHorpathconf. Allocate it usingmalloc. Write into that buffer usingsnprintf._alloca. That way, the memory will automatically be freed.