Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Message-ID | <4FDB48C6.6030802@loria.fr> (permalink) |
|---|---|
| Date | 2012-06-15 16:37 +0200 |
| From | Jens Gustedt <jens.gustedt@loria.fr> |
| Newsgroups | comp.lang.c |
| Subject | Re: Determining the 'type' of a variable, if only its name is given |
| References | <caa6501b-646a-4ca3-85a2-a15bf7271d90@h41g2000yqm.googlegroups.com> <966f3de9-bf1f-418a-b3e0-fbeecfa241a5@j10g2000yqd.googlegroups.com> |
| Organization | Guest of ProXad - France |
Am 15.06.2012 10:51, schrieb John Reye:
> is it possible, to determine the 'type' of a variable, if only its
> name is given.
[snip things about oldish C99]
> Is there any other way, to determine if a variable var is signed or
> unsigned, if sizeof(var) < sizeof(int) ???
with C11's _Generic you may do that, provided your implementation
hasn't extended integer types that are narrower than int,
you can do something horrible like
_Generic(var,
default: use_the_previous_method(var),
char: (CHAR_MAX < UCHAR_MAX),
char const: (CHAR_MAX < UCHAR_MAX),
char volatile: (CHAR_MAX < UCHAR_MAX),
char const volatile: (CHAR_MAX < UCHAR_MAX),
char _Atomic: (CHAR_MAX < UCHAR_MAX),
char const _Atomic: (CHAR_MAX < UCHAR_MAX),
char volatile _Atomic: (CHAR_MAX < UCHAR_MAX),
char const volatile _Atomic: (CHAR_MAX < UCHAR_MAX),
_Bool: 0,
_Bool const: 0,
_Bool volatile: 0,
_Bool const volatile: 0,
_Bool _Atomic: 0,
_Bool const _Atomic: 0,
_Bool volatile _Atomic: 0,
_Bool const volatile _Atomic: 0,
signed char: 1,
signed short: 1,
signed char const: 1,
signed short const: 1,
signed char volatile: 1,
signed short volatile: 1,
signed char const volatile: 1,
signed short const volatile: 1,
signed char _Atomic: 1,
signed short _Atomic: 1,
signed char const _Atomic: 1,
signed short const _Atomic: 1,
signed char volatile _Atomic: 1,
signed short volatile _Atomic: 1,
signed char const volatile _Atomic: 1,
signed short const volatile _Atomic: 1,
unsigned char: 0,
unsigned short: 0,
unsigned char const: 0,
unsigned short const: 0,
unsigned char volatile: 0,
unsigned short volatile: 0,
unsigned char const volatile: 0,
unsigned short const volatile: 0,
unsigned char _Atomic: 0,
unsigned short _Atomic: 0,
unsigned char const _Atomic: 0,
unsigned short const _Atomic: 0,
unsigned char volatile _Atomic: 0,
unsigned short volatile _Atomic: 0,
unsigned char const volatile _Atomic: 0,
unsigned short const volatile _Atomic: 0
)
- the case for "char" works since "unsigned char" can't have padding
bits
- _Bool is unsigned per definition
- then for all cases you have to distinguish all qualified types. at
least as quickly I didn't come up with an idea that would force an
conversion to an rvalue such that it would drop all qualifiers, and
wouldn't promote to the rank of "int"
Jens
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Determining the 'type' of a variable, if only its name is given John Reye <jononanon@googlemail.com> - 2012-06-15 01:47 -0700
Re: Determining the 'type' of a variable, if only its name is given John Reye <jononanon@googlemail.com> - 2012-06-15 01:51 -0700
Re: Determining the 'type' of a variable, if only its name is given James Kuyper <jameskuyper@verizon.net> - 2012-06-15 08:18 -0400
Re: Determining the 'type' of a variable, if only its name is given "BartC" <bc@freeuk.com> - 2012-06-15 13:43 +0100
Re: Determining the 'type' of a variable, if only its name is given Noob <root@127.0.0.1> - 2012-06-15 17:02 +0200
Re: Determining the 'type' of a variable, if only its name is given Robert Miles <milesrf@Usenet-News.net> - 2012-07-23 23:20 -0500
Re: Determining the 'type' of a variable, if only its name is given pete <pfiland@mindspring.com> - 2012-06-15 08:21 -0400
Re: Determining the 'type' of a variable, if only its name is given Jens Gustedt <jens.gustedt@loria.fr> - 2012-06-15 16:37 +0200
Re: Determining the 'type' of a variable, if only its name is given Ian Collins <ian-news@hotmail.com> - 2012-06-16 09:27 +1200
Re: Determining the 'type' of a variable, if only its name is given Jens Gustedt <jens.gustedt@loria.fr> - 2012-06-16 09:38 +0200
Re: Determining the 'type' of a variable, if only its name is given Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-22 20:42 -0700
Re: Determining the 'type' of a variable, if only its name is given Jens Gustedt <jens.gustedt@loria.fr> - 2012-06-23 14:41 +0200
Re: Determining the 'type' of a variable, if only its name is given Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-24 10:15 -0700
Re: Determining the 'type' of a variable, if only its name is given Tim Rentsch <txr@alumni.caltech.edu> - 2012-06-22 20:31 -0700
csiph-web