Celtoys / Remotery

Single C file, Realtime CPU/GPU Profiler with Remote Web Viewer
Apache License 2.0
3.11k stars 264 forks source link

Logical 'or' of equal expressions warning #170

Closed aganm closed 3 years ago

aganm commented 3 years ago

This part https://github.com/Celtoys/Remotery/blob/7e6886932e904c95c134d6af2f3ee1cfae69dba1/lib/Remotery.c#L2476-L2477

Checks for values which are defined to the same thing

#define EAGAIN          11      /* Try again */
#define EWOULDBLOCK     EAGAIN  /* Operation would block */

gcc gives me a warning Logical 'or' of equal expressions warning, should this be fixed?

dwilliamson commented 3 years ago

Looks like most modern systems define them to be the same value and there's a bunch of legacy systems that don't. The code appears to be correct, as advised by the GNU documentation:

Portability Note: In many older Unix systems, this condition was indicated by EWOULDBLOCK, which was a distinct error code different from EAGAIN. To make your program portable, you should check for both codes and treat them the same.

What seems to be left is working around the specific warning, maybe with an #ifdef that checks the values are equal before comparison.

Given the potential value of handling EAGAIN on the more obscure systems, it seems the function name TCPSocketWouldBlock is also not accurate enough.