Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: IsUnsigned() function? Message-ID: <17115@haddock.ima.isc.com> Date: 18 Jul 90 20:16:14 GMT References: <1990Jul16.214155.5087@Neon.Stanford.EDU> Reply-To: karl@kelp.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 13 In article <1990Jul16.214155.5087@Neon.Stanford.EDU> jhsu@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@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint