[comp.lang.c] IsUnsigned function?

john.russell@canremote.uucp (JOHN RUSSELL) (07/22/90)

None of the answers so fa{ has addressed the question of "space 
efficient".  Any solution that uses "if" stands a chance of generating 
branch instructions.  Any solution that explicitly returns 0 or 1 will 
generate a "clear" instruction, and maybe a "move" instruction with a 16
or 32-bit operand.

The question might also have been checking for knowledge of a particular
chip instruction set, eg. on 68K a moveq.l #1 instruction allows you to 
explicitly return a 1 without wasting 32 bits to hold the operand. 
 
I won't post my solution  (after all, Microsoft is presumably still
asking this question), but is compiles to 3 instructions plus function
linking stuff; one of the instructions has a 16-bit operand, the others
are register-to-register.  (This is on a 68K without any optimization.)
 
John
---
 * Via ProDoor 3.1R 

jak@sactoh0.UUCP (Jay A. Konigsberg) (07/25/90)

In article <15303b1aa0bf26a8c5d4@canremote.uucp> john.russell@canremote.uucp (JOHN RUSSELL) writes:
>None of the answers so fa{ has addressed the question of "space 
>efficient".
>
That isn't the only question. Its also a matter of portability.

>I won't post my solution  (after all, Microsoft is presumably still
>asking this question)
>
I think you are missing a basic point. There is no "best" solution. Rather,
its a matter of understanding the pro's and con's of different approaches.



-- 
-------------------------------------------------------------
Jay @ SAC-UNIX, Sacramento, Ca.   UUCP=...pacbell!sactoh0!jak
If something is worth doing, its worth doing correctly.