Closed wijagels closed 6 years ago
Can you provide some context for changing things? I cannot remember why I chose using if
instead of case
, but the fact that I use case in all other areas where I defined the CSTRINGIFY macro (e.g., https://github.com/rescrv/Replicant/blob/master/common/macros.h) implies to me that I made a conscious choice of if vs. switch at the time.
Sure, the idea is to make it easier for the compiler to optimize strerror. Using a switch also forces any dead-code to be removed, since collisions must be explicitly resolved, instead of creating an unreachable branch. The likely reason for using an if is that there are a few error codes that collide such as EDEADLOCK
and EDEADLK
(POSIX). Linux violates POSIX by having EWOULDBLOCK
equal EAGAIN
. I didn't see any other collisions, but checking other systems is a good idea.
Godbolt for difference