🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2174

Re: this unsigned business

#2174
From: Norman Diamond
Date: Thu, 01 Oct 1992 02:57
20 lines
1480 bytes
In article <711@mtndew.Tustin.CA.US> friedl@mtndew.Tustin.CA.US (Stephen Friedl) writes:
>     Let's say that I've got an int whose legal range is 0 to 100,
>and I want to validate it (say) upon entry to a function.  Is this
>a portable way to do it?
>  foo(v) int v; {
>    if ( (unsigned int) vu > 100) printf("value out of range!\n");
>    /* must be valid */

It's portable because conversions from int to unsigned int are defined
and because MAX_UINT is sufficiently large for your purpose.

>     Note that I am not looking for the aesthetics of this -- it's
>a trick that will just confuse somebody

You bet!  After all, you print "value out of range!\n" and then fall
through to the next line, assuming "must be valid" :-)
--
Norman Diamond       diamond@jit081.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
"Yeah -- bad wiring.  That was probably it.  Very bad."
Technical Details
Message-ID: <1992Oct1.025724.12830@nntpd.lkg.dec.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!deccrl!news.crl.dec.com!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond
References: <711@mtndew.Tustin.CA.US>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!decwrl!deccrl!news.crl.dec.com!pa.dec.com!nntpd2.cxo.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond
From: diamond@jit345.bad.jit.dec.com (Norman Diamond)
Subject: Re: this unsigned business
Message-ID: <1992Oct1.025724.12830@nntpd.lkg.dec.com>
Sender: usenet@nntpd.lkg.dec.com (USENET News System)
Reply-To: diamond@jit.dec.com (Norman Diamond)
Organization: Digital Equipment Corporation Japan , Tokyo
References: <711@mtndew.Tustin.CA.US>
Date: Thu, 1 Oct 1992 02:57:24 GMT
Lines: 20