How does one construct a mask for th

stevel at haddock.UUCP stevel at haddock.UUCP
Sat Mar 9 14:49:30 AEST 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.



More information about the Comp.lang.c mailing list