IsUnsigned() function?
Karl Heuer
karl at haddock.ima.isc.com
Wed Jul 25 10:44:37 AEST 1990
In article <615 at tetrauk> rick at tetrauk.UUCP (Rick Jones) writes:
>I'm suprised that very few people seems to have grasped what the question was
>about.
It's because the question was so poorly worded (as posted; I don't know if it
was asked the same way). Maybe that was the intent: to see if the interviewee
would give the correct response, "What do you mean?", rather than immediately
starting to write code.
>#define IsUnsigned(a) (a >= 0 && ~a >= 0)
I think my version is more likely to fold into a compile-time constant. (I
used `((a)*0-2)/2+1 != 0', which is intended to be fairly robust even against
questionable compilers.) And why assume 2's-complement if you don't have to?
Trivia question: under what circumstances will Rick's macro produce the wrong
answer to the presumed question?
Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint
More information about the Comp.lang.c
mailing list