*Consider an ANSI compliant compiler on a machine using 2's
complement arithmetic for integers. The task is
to figure out whether a variable used for integers is signed or not.
One suggested solution is to write a macro like the following:
#define IS_UNSIGNED( var ) \
( (var) >= 0 && ~(var) >= 0 )
(a) Will this macro work for all possible integer values or are there
any exceptions? (If you find any exceptions,
you are encouraged to find a solution that will get rid of those
exceptions.)
(b) If the variable is a type instead of a variable, how would the
macro above be rewritten?
#define IS_UNSIGNED( TYPE ) \
(c) Is it possible to write a function to do this job instead of a
macro? If yes, show how the the macro shown
above can be rewritten as a function. If it cannot be cast as a
function, explain why not. [Either write below,
the IsVarUnsigned( ... ) function or give your reasoning.]
complement arithmetic for integers. The task is
to figure out whether a variable used for integers is signed or not.
One suggested solution is to write a macro like the following:
#define IS_UNSIGNED( var ) \
( (var) >= 0 && ~(var) >= 0 )
(a) Will this macro work for all possible integer values or are there
any exceptions? (If you find any exceptions,
you are encouraged to find a solution that will get rid of those
exceptions.)
(b) If the variable is a type instead of a variable, how would the
macro above be rewritten?
#define IS_UNSIGNED( TYPE ) \
(c) Is it possible to write a function to do this job instead of a
macro? If yes, show how the the macro shown
above can be rewritten as a function. If it cannot be cast as a
function, explain why not. [Either write below,
the IsVarUnsigned( ... ) function or give your reasoning.]