Misleading type cast in function modbus_tcp_listen()
There is a misleading type cast in function modbus_tcp_listen().
I think
if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, (char *) &enable, sizeof(enable)) ==
should be replaced by
if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, (void *) &enable, sizeof(enable)) ==
similar to modbus_tcp_pi_listen(), or
if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) ==
I prefer the later one as to my understanding there is no type cast needed at this point at all.
dde16d55 breaks Windows builds with GCC 14 and later, requiring -fpermissive in order to compile. Winsock setsockopt uses const char * for optval rather than const void * as it is on POSIX.
int WSAAPI setsockopt(
[in] SOCKET s,
[in] int level,
[in] int optname,
[in] const char *optval,
[in] int optlen
);
GCC 14 and later is strict about pointer casts and rejects the implicit cast from int * to const char *. The explicit char * cast was probably used to silence the warning that is now an error.
@skeeto I see the problem. Sorry, I was not aware that the Winsock API is not compatible with POSIX in that regard.