- Fixes compilation errors, when building under Windows (e.g. VS2015):
..\src\optparse.c(195): error C2057: expected constant expression
..\src\optparse.c(195): error C2466: cannot allocate an array of
constant size 0
..\src\optparse.c(195): error C2133: 'optstring': unknown size
- Variable length arrays are not currently supported in Visual Studio
- Use malloc() instead of variable length array in case of MSC
#include <stdio.h>
+#ifdef _MSC_VER
+#include <stdlib.h> /* for malloc(), free() */
+#endif
#include "optparse.h"
#define opterror(options, format, ...) \
const struct optparse_long *longopts,
int *longindex)
{
+#ifdef _MSC_VER
+ /* Variable length arrays are not currently supported in Visual Studio */
+ char *optstring = malloc(optstring_length(longopts));
+#else
char optstring[optstring_length(longopts)];
+#endif
optstring_from_long(longopts, optstring);
int result = optparse(options, optstring);
if (longindex != NULL) {
if (longopts[i].shortname == options->optopt)
*longindex = i;
}
+#ifdef _MSC_VER
+ free(optstring);
+#endif
return result;
}