Ahhh!
Here's a rewrite of the previous post, with BETTER FORMATTING:
Hi,
is it possible, to determine the 'type' of a variable, if only its
name is given.
With 'type', I don't mean the exact type, such as enum, but instead
the following information:
a) sizeof
b) signed or unsigned
a) ... is always easy to determine: sizeof(var) !!
b) ... is - as far as I know - only easy to determine,
if sizeof(var)>= sizeof(int)
Here are the macros I use:
#define WIDTH_GE_INT(EXPR) (sizeof(EXPR) >= sizeof(int))
#define EXPR_OR_VAR_IS_SIGNED(EXPR) \
(WIDTH_GE_INT(EXPR) \
? P99_SIGNED(EXPR) \
: /* EXPR is a variable */ \
/* GCC extension - "statement expressions" */ \
({int _temp; int _is_signed; \
_temp = EXPR , \
_is_signed = (!((EXPR = -1) > 0)) , \
EXPR = _temp , \
_is_signed;}))
Get Jens Gustedt's fantastic P99_SIGNED macro here:
http://p99.gforge.inria.fr/p99-html/...eb39ccac28ebd8...
As you can see above, if sizeof(var) < sizeof(int), I actually have to
access the variable in order to determine if it is signed or unsigned.
I really do not like this.
Is there any other way, to determine if a variable var is signed or
unsigned, if sizeof(var) < sizeof(int) ???
Thanks.
J.
PS: Is it possible, to write the above macros in standard C, without
using gcc's extension of "statement expressions"