-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No specified C++ standard in make files and potential issues #103
Comments
* Set C++11 as minimal standard * Fix C++ Makefile in macOS * Update the C++ WebUI header to use references (#103) * Update `webui_return_string()` argument from `char*` to `const char*`
Thank you, Giuseppe, for pointing this out. Honestly, this project is purely C99, but someone on Reddit requested a C++ wrapper, so I created the C++ wrapper in 20-25 minutes in a rush... and for sure, it's not complete and needs improvements. You are right about the unnecessary strings copy, so I update it to use references instead of values, especially when APIs take About the standard, the WebUI C++ wrapper is relatively small and easy, so selecting a minimum standard as C++11 is enough. This helps developers who are using WebUI in old embedded/PC devices. On the other hand, anyone can easily modify the Fix: cdf67b1 |
This fixes the problem, so I'm closing the thread. However, I want to point out that taking |
That's true, but unfortunately, this is the nature of C++. The best solution is providing overloads for both |
Saying that is the nature of C++ does not feel right to me; I think is more the nature of This is not a big deal, if I'm being honest, since the compiler will optimize the copy if the string literal can fit in the SSO, and the temporary object will be moved or emplaced instead of being copied. But even though I'm a C++ guy, I think that a
The last option is to basically reimplement Each of these ways of dealing with strings is valid in my opinion, and each way has it's downside and it's strengths; I'm just pointing out that strings are hard, and the API that deals with them should be carefully considered. |
I already taught about using Honestly, using |
I was already preparing a patch with some minor stuff. If you feel like doing the standard change I will add the string_view and wait for your commit. |
The make files responsible for compiling the C++ examples in the project currently lack a selected C++ standard, and there is no mention of the targeted C++ standard within the project.
This could lead to:
Contributors may face difficulties in determining which C++ language features are available to them. For instance, the current implementation of the
window::return_string
member function in the C++ bindings:This demonstrates passing a string by value, which can be computationally expensive. However, in this particular case, such copying is unnecessary, as the function
webui_return_string
already creates a copy of the string. To mitigate this, there are two main approaches: passing thestd::string
asconst std::string&
or utilizingstd::string_view
. The latter is the recommended approach due to its ability to alias to various types and potentially avoid costly calls to thestd::string
constructor. Nevertheless, adoptingstd::string_view
requires C++20, and implementing this change with the current make files will result in compilation errors.By not explicitly defining the C++ standard, the compilers will resort to defaulting to a particular standard based on the compiler version. For instance, clang 15 will default to using C++14, while clang 16 will default to C++17. This inconsistency can lead to the infamous "it works on my PC" problem.
Additionally, considering the nature of the project and the potential benefits of modern C++ features, it is recommended to adopt at least C++20 as the targeted standard within the make files.
The text was updated successfully, but these errors were encountered: