IsUnsigned() function?
netnews dptg
netnews at mtunh.ATT.COM
Fri Jul 20 14:12:28 AEST 1990
How about this:
IsUnsigned (a)
int a;
{
return( !(a >> ((sizeof(int)*8)-1)));
}
The only real assumption that this function makes is that
there are 8 bits in a byte (a fair assumption I think).
If you don't care about portability (I do, though) and like to make
more assumptions (like the size of the int on your system)
you can make it even shorter:
4 byte int:
IsUnsigned (a)
int a;
{
return( !(a >> 31));
}
2 byte int:
IsUnsigned (a)
int a;
{
return( !(a >> 15));
}
BTW: What you have experienced says much more about Microsoft than
about yourself. Don't let it eat you.
Ralph Hayon
AT&T Bell Laboratories,
Middletown, NJ
More information about the Comp.lang.c
mailing list