I have a variable id
whose type may vary from platform to platform. In several places, existing code (which I cannot change) sets the id
to a "negative" value, e.g.
id = -ETIMEDOUT;
On some platforms, id
might be signed; on others, it may be unsigned. I want to test to see if the id
was set to -ETIMEDOUT
. The naive attempt below subtly fails when id
is unsigned:
if(id == -ETIMEDOUT)
How do I concisely test for this condition?
@jlahd has posted a good answer. I would like to offer an alternative though.
I think that this will do similar but there is a problem with it. It isn't in the C standard and is a GCC extension.
You can read a little more about it here
Verbatim quote of @rici's comment: