IsUnsigned() function?

Jay A. Konigsberg jak at sactoh0.UUCP
Thu Jul 19 08:51:48 AEST 1990


In article <1990Jul16.214155.5087 at Neon.Stanford.EDU> jhsu at Neon.Stanford.EDU (Jeffrey H. Hsu) writes:
>
>	How would you write a space efficient algorithm/function in C that 
>takes in an integer and returns 0 if signed and 1 if unsigned?
>

I would bet that they had something like this in mind.

--------------------------------------------------------------------------
#define MASK 10000000
#define TRUE 1
#define FALSE 0

main()
{
signed(1)  ? printf("unsigned\n") : printf("signed\n");
signed(-1) ? printf("unsigned\n") : printf("signed\n");
}

signed(number)
long number;
{
if( number & MASK )
    return(FALSE);
else
    return(TRUE);
}
-- 
-------------------------------------------------------------
Jay @ SAC-UNIX, Sacramento, Ca.   UUCP=...pacbell!sactoh0!jak
If something is worth doing, its worth doing correctly.



More information about the Comp.lang.c mailing list