IsUnsigned() function?
Karl Heuer
karl at haddock.ima.isc.com
Thu Jul 19 06:16:14 AEST 1990
In article <1990Jul16.214155.5087 at Neon.Stanford.EDU> jhsu at Neon.Stanford.EDU (Jeffrey H. Hsu) writes:
>How would you write a space efficient algorithm/function in C that
>takes in an integer and returns 0 if signed and 1 if unsigned?
Define your terms. Is this to be a function or a macro? If a function, then
its argument must have a type known at compile-time: what type is it? Is the
goal to determine the signedness of the type of the argument, or the value?
A non-trivial specification is to write a macro to find the signedness of the
(promoted) type of its argument expression. One way to do this is
#define IsUnsigned(x) (((x)*0-2)/2+1 != 0)
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