public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* long long bit-fields
@ 2003-03-30 19:14 Falk Hueffner
  2003-03-31  8:46 ` Segher Boessenkool
  0 siblings, 1 reply; 4+ messages in thread
From: Falk Hueffner @ 2003-03-30 19:14 UTC (permalink / raw)
  To: gcc

Hi,

PR c/6346, middle-end/7018 and target/9620 deal with long long
bit-fields. I guess part of the confusion comes from the fact that the
C standard doesn't specify how they should behave (at least I couldn't
find it). So what is the following program supposed to print?

#include <stdio.h>

int
main(int argc, char *argv[]){
    struct {
	unsigned long long ull31a: 31;
	unsigned long long ull31b: 31;
    } x;
    x.ull31a = -1;
    x.ull31b = 1;

    printf("%016llx %016llx %016llx\n",
	   (x.ull31a << 48) >> 48,
	   (x.ull31a << 16),
	   (x.ull31b << 48));
}

Candidates are:

ffffffffffffffff ffffffffffff0000 0000000000010000 (gcc)
ffffffffffffffff 00007fffffff0000 0001000000000000 (Compaq C)
000000000000ffff 00007fffffff0000 0001000000000000 (g++)
0000000000000000 ffffffffffff0000 0000000000000000 (Compaq C++)

-- 
	Falk

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: long long bit-fields
  2003-03-30 19:14 long long bit-fields Falk Hueffner
@ 2003-03-31  8:46 ` Segher Boessenkool
  2003-03-31  9:22   ` Falk Hueffner
  0 siblings, 1 reply; 4+ messages in thread
From: Segher Boessenkool @ 2003-03-31  8:46 UTC (permalink / raw)
  To: Falk Hueffner; +Cc: gcc

Falk Hueffner wrote:
> Hi,
> 
> PR c/6346, middle-end/7018 and target/9620 deal with long long
> bit-fields. I guess part of the confusion comes from the fact that the
> C standard doesn't specify how they should behave (at least I couldn't
> find it). So what is the following program supposed to print?
> 
> #include <stdio.h>
> 
> int
> main(int argc, char *argv[]){
>     struct {
> 	unsigned long long ull31a: 31;
> 	unsigned long long ull31b: 31;
>     } x;
>     x.ull31a = -1;
>     x.ull31b = 1;
> 
>     printf("%016llx %016llx %016llx\n",
> 	   (x.ull31a << 48) >> 48,
> 	   (x.ull31a << 16),
> 	   (x.ull31b << 48));
> }
> 
> Candidates are:
> 
> ffffffffffffffff ffffffffffff0000 0000000000010000 (gcc)

Correct (the integer promotions promote an unsigned integer
bit-field to a signed integer, if it fits).

> ffffffffffffffff 00007fffffff0000 0001000000000000 (Compaq C)

Not correct.

> 000000000000ffff 00007fffffff0000 0001000000000000 (g++)
> 0000000000000000 ffffffffffff0000 0000000000000000 (Compaq C++)

Don't know about C++, sorry.


Segher


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: long long bit-fields
  2003-03-31  8:46 ` Segher Boessenkool
@ 2003-03-31  9:22   ` Falk Hueffner
  2003-04-01  0:11     ` Segher Boessenkool
  0 siblings, 1 reply; 4+ messages in thread
From: Falk Hueffner @ 2003-03-31  9:22 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc

Segher Boessenkool <segher@koffie.nl> writes:

> Falk Hueffner wrote:
> > PR c/6346, middle-end/7018 and target/9620 deal with long long
> > bit-fields. [...]
>
> Correct (the integer promotions promote an unsigned integer
> bit-field to a signed integer, if it fits).

Okay. Then we can close middle-end/7018. Most other bit-field bugs
seem to be caused by casts to the bit-field's type getting discarded
erraneously, by the folder presumably. I'll try to have a look at that
some time in the future.

How about:

    struct { unsigned long long ull31a: 33; } x = { -1 };
    printf("%016llx\n", (x.ull31a << 48) >> 48);

We don't currently promote to signed long long if it fits. Should we?

-- 
	Falk

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: long long bit-fields
  2003-03-31  9:22   ` Falk Hueffner
@ 2003-04-01  0:11     ` Segher Boessenkool
  0 siblings, 0 replies; 4+ messages in thread
From: Segher Boessenkool @ 2003-04-01  0:11 UTC (permalink / raw)
  To: Falk Hueffner; +Cc: gcc

Falk Hueffner wrote:
> How about:
> 
>     struct { unsigned long long ull31a: 33; } x = { -1 };
>     printf("%016llx\n", (x.ull31a << 48) >> 48);
> 
> We don't currently promote to signed long long if it fits. Should we?

Yes.  But IMHO, of course.


Segher

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-04-01  0:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-30 19:14 long long bit-fields Falk Hueffner
2003-03-31  8:46 ` Segher Boessenkool
2003-03-31  9:22   ` Falk Hueffner
2003-04-01  0:11     ` Segher Boessenkool

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).