I have the following C++ error: ../../../../../src/osd/messui/messui.cpp: In function…
- User
I have the following C++ error:
../../../../../src/osd/messui/messui.cpp: In function 'BOOL AddSoftwarePickerDirs(HWND, LPCSTR, LPCSTR)': ../../../../../src/osd/messui/messui.cpp:570:7: error: variable length array 's' is used [-Werror=vla] 570 | char s[a] = { };
The function is:
static BOOL AddSoftwarePickerDirs(HWND hwndPicker, LPCSTR pszDirectories, LPCSTR pszSubDir) { printf("AddSoftwarePickerDirs: Begin\n");fflush(stdout); if (!pszDirectories) return false;
codesize_t a = strlen(pszDirectories) + 1; char s[a] = { }; string pszNewString; strcpy(s, pszDirectories); LPSTR t1 = strtok(s,";"); while (t1) { printf("AddSoftwarePickerDirs: Folder %s\n",t1);fflush(stdout); if (pszSubDir) pszNewString = t1 + string("\\") + pszSubDir; else pszNewString = t1; bool folder_exist = (_access(t1,6) == 0) ? true : false; if (folder_exist) { printf("AddSoftwarePickerDirs: newstring %s\n",pszNewString.c_str());fflush(stdout); (void)SoftwarePicker_AddDirectory(hwndPicker, pszNewString.c_str()); } printf("AddSoftwarePickerDirs: On to the next\n");fflush(stdout); t1 = strtok (NULL, ";"); } return true;}
- Assistant
- User
Many thanks for the "Alternative" solution! This works fine.
- Assistant
You’re very welcome!
I’m glad thestd::stringsolution worked well for you. If you run into any more C++ questions or want to improve the code further, feel free to ask. Happy coding! 🚀 - User
I have the following C++ error:
../../../../../src/osd/messui/emu_opts.cpp: In function 'string GetIniDir()': ../../../../../src/osd/messui/emu_opts.cpp:167:7: error: variable length array 'dir0' is used [-Werror=vla] 167 | char dir0[global_ini.length()+2] = { }; | ^~~~
The function is:
string GetIniDir() { //string global_ini = emu_global.value(OPTION_INIPATH);printf("GetIniDir = %s\n",global_ini.c_str()); string global_ini = dir_get_value(7);printf("GetIniDir = %s\n",global_ini.c_str()); if (global_ini.empty()) return GetEmuPath() + PATH_SEPARATOR + "ini";
codechar dir0[global_ini.length()+2] = { }; strcpy(dir0, global_ini.c_str()); char* t0 = strtok(dir0, ";"); osd::directory::ptr b = osd::directory::open(t0); if (t0 && b) { } else return GetEmuPath() + PATH_SEPARATOR + "ini"; // see if relative or absolute path global_ini = t0; bool is_absolute = false; if ((global_ini.length() > 4) && (std::isalpha(global_ini[0])) && (global_ini[1] == ':') && (global_ini[2] == '\\')) is_absolute = true; if ((global_ini.length() > 4) && (global_ini[0] == '\\') && (global_ini[1] == '\\')) is_absolute = true; if (is_absolute) return global_ini; else return GetEmuPath() + PATH_SEPARATOR + global_ini; - Assistant
The error is exactly the same underlying issue as before: you are declaring a on the stack, which is not allowed in standard C++:
- User
The "Recommended fix using std::string" are working! Very helpful. Much thanks!
- Assistant
You’re very welcome!
Glad to hear thestd::stringfix is working perfectly for you. If you ever need more C++ help or anything else, just let me know. Happy coding! 😊🚀