Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucsd!pacbell.com!decwrl!bacchus.pa.dec.com!deccrl!decvax.dec.com!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: IsUnsigned() function? Message-ID: <17147@haddock.ima.isc.com> Date: 25 Jul 90 00:44:37 GMT References: <1990Jul16.214155.5087@Neon.Stanford.EDU> <2936@mtung.ATT.COM> <1990Jul22.154326.19680@ux1.cso.uiuc.edu> <615@tetrauk> Reply-To: karl@kelp.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 19 In article <615@tetrauk> rick@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@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint