Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #22580

Re: Determining the 'type' of a variable, if only its name is given

Message-ID <4FE5B982.3080100@loria.fr> (permalink)
Date 2012-06-23 14:41 +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> <4FDB48C6.6030802@loria.fr> <kfntxy2u215.fsf@x-alumni2.alumni.caltech.edu>
Organization Guest of ProXad - France

Show all headers | View raw


Hi

Am 23.06.2012 05:42, schrieb Tim Rentsch:
> Jens Gustedt <jens.gustedt@loria.fr> writes:
>
>> 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),
>>         [snip remainder]
> 
> In most cases I expect this approach will work fine, but unfortunately
> it doesn't always,

It did some more experiments with this and actually found that the
handling of qualified types is not very well designed with this new
_Generic tool. In the case it was asked here (for a variable, i.e an
lvalue) it seems consistent, but for rvalues it is completely
underspecified.

I'll post a question comp.std.c about this

> specifically for bitfields.

the signedness of bitfields is really a special case oddity. What
should _Generic trigger, here. The declared type or the effective
type?

A bitfield that is declared with just "int" could (implementation
defined) well be unsigned in nature. To the extreme on a system with
32 bit wide "int", a bit field with specification "int a:32" could be
unsigned.

> Btw, the many redundant parentheses are, well, redundant.

but not superficial

coding styles vary, as you probably know

Jens

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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