-
Notifications
You must be signed in to change notification settings - Fork 7.6k
WiFiClient and related macros - troubles when using forward declarations #9891
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
Comments
that would not work for return value of NetworkServer::accept() |
@cziter15 can you provide a basic test? Also I suggest you switch to NetworkClient when you detect Arduino 3. As @JAndrassy said, this will not work everywhere either. |
It's easy to trick it using fd() as we can pass fd() to underying implementation, but... there's WiFIClientSecure, which inherits from WiFiClient and this cannot be trivially handled, because of pointer-casting. Looks like there's no solution to this. Even using #define is not a good idea. Anyway, isn't it possible to define these "links" same way as ARDUINO macro? |
Mhh, core 3.0.0 has breaking changes, why trying to be backwards compatible where it is not possible to do it correctly? Imho this is the wrong way. The user code needs to be adopted to the changes. Every "trickery" bites back some day... |
I think it is possible, but it will require wrapper-like approach. Selective define inside header is bad, because it forces you to include the header - forward declaration is not possible. |
In your CPP (should include #if ESP_ARDUINO_VERSION_MAJOR >= 3
class NetworkClient;
#else
class WiFiClient;
#endif Or #if ESP_ARDUINO_VERSION_MAJOR >= 3
#define WiFiClient NetworkClient;
#endif
class WiFiClient; |
I believe this is more of a consistency issue than a technical one. Current solution, which involves using macros in In my opinion, the first approach is acceptable, but it should be complemented with an implementation in the .cpp file like this: #if ESP_ARDUINO_VERSION_MAJOR >= 3
#include <NetworkClient.h>
#else
#include <WiFiClient.h>
#endif A more effective (in context of You can see an example of this in the WinTypes.h file on GitHub: WinTypes.h. I feel that half-measures are being applied. In my opinion, either the definitions should be global (defined using compiler options, similar to the @JAndrassy, I'm just discussing the issue and wondering if there's room for improvement. I've resolved it on my end by using global definitions, similar to the approach used in the |
How about a warning instead? |
@me-no-dev Ah, yes, I was thinking of a warning. Busy day... :) |
@me-no-dev warning will be issued only if the user included WiFiClient or related files directly. If using WiFi.h then it will remain unnoticed, but I don't have any idea in my mind on this. The rest looks good for me. |
@cziter15 try the latest changes please :) typedefs instead of defines |
I think it's better to leave |
Version
v3.0.1
Description
The classes related to networking, such as WiFiClient and WiFiServer, have been renamed to NetworkClient, NetworkServer, and similar names. To preserve backward compatibility, macros (defines) have been introduced, but they are embedded within the class headers.
This modification can create issues if you have utilized forward declarations in your headers. As a result, users are now compelled to include the full implementation in every instance.
A better approach would be to use inheritance rather than relying on defines.
The text was updated successfully, but these errors were encountered: