Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!bellcore!decvax!cca!ima!haddock!stevel From: stevel@haddock.UUCP Newsgroups: net.lang.c Subject: Re: How does one construct a mask for th Message-ID: <381@haddock.UUCP> Date: Fri, 8-Mar-85 23:49:30 EST Article-I.D.: haddock.381 Posted: Fri Mar 8 23:49:30 1985 Date-Received: Mon, 11-Mar-85 05:07:31 EST Lines: 30 Nf-ID: #R:brl-tgr:-884900:haddock:12400022:000:1022 Nf-From: haddock!stevel Mar 7 15:50:00 1985 > > #define MSB (~(-1>>1)) > > Surprise, this doesn't even work on VAX's and PDP -11's. -1>>1 > is still -1. Be careful when coming up with ideas like these. > C has also been implemented on ones-complement (and subtractive > arithmatic) machines. Right shifting of signed quantities is > defined to be machine depenedant in C. Next time I'll try it on the vax compiler instead of my own pcc based one. How about this. msb(){ register unsigned a; return( ~((a= -1)>>1) ); } or for the truer minimalists msb(){register unsigned a;return~((a= -1)>>1);} or for the one who like to live dangerously static unsigned _foo_bar #define MSB (~((_foo_bar= -1) >> 1)) I know what you are saying Jim. What if I get a signal while prosessing the macro and invoke it again. Well the word on the vax is that you are in luck it only uses the in register value. Steve Ludlum, decvax!yale-co!ima!stevel, {ihnp4!cbosgd}!ima!stevel PS these macros/functions are certified to work on V.2.2 vax C compiler for whatever thats worth.