On Fri, Apr 28, 2023 at 10:33 AM, Bob Jacobsen wrote:
Does the start of this loop de-reference the `client` variable before it’s been set for the first time?
No, the loop does not de-reference the client variable before it's been set for the first time. In the loop, the first line of code checks if the client is not connected:
if (!client.connected()) {
If the client is not connected, the client.stop(); line is executed. However, since the client hasn't been set yet, calling stop() on it will have no effect.
?
Next, the client = server.available(); line is executed. This line assigns an available client connection to the client variable. If there is no available client connection, the client variable will be assigned an instance of the EthernetClient class that represents a non-connected client. In either case, the client variable will be properly initialized before it's used in the rest of the loop.
?
From this point forward, the client variable will always be initialized before it's used in the loop. The code is structured in a way that ensures the client variable is never de-referenced before it has been properly set.
Tom