🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Robert R. Henry Wed, 28 Oct 1992 17:15
gdb4.7 lossage with extracting bitfield enums (resending)
#20
Author: Robert R. Henry
Date: Wed, 28 Oct 1992 17:15
52 lines
1542 bytes
gdb4.7 target==sparc, host==sparc (g++ from gcc2.2.2) does
a sign extension when it extracts enumerations contained in bit fields;
gdb4.6 does not do the sign extension, and neither does gcc from gcc2.2.2.
(Note that enums contained in bitfields are legal in c++, since they
are integral types)

For the program at the bottom,
breaking at the first printf in main,
and doing
  (gdb4.7) print e
  $1 = {
    x = -2
  }
  (gdb4.7) print u
  $2 = {
    x = 2
  }
whereas in gdb4.6 doing the same thing:
  (gdb4.6) print e
  $1 = {
    x = VAL2
  }
  (gdb4.6) print u
  $2 = {
    x = 2
  }
is better, and agrees in the sign-extendedness behaviour
with the output of executing the program:
  VAL2 = 2
  e.x = 2
  u.x = 2

#include <stdio.h>

typedef enum { VAL0 = 0, VAL1 = 1, VAL2 = 2 } junk_t;

struct e_struct { junk_t x : 2; };

struct ui_struct { unsigned int x : 2; };

main()
{
    struct e_struct e;
    struct ui_struct u;

    e.x = VAL2;
    u.x = VAL2;

    printf("VAL2 = %d\n", VAL2);
    printf("e.x = %d\n", e.x);
    printf("u.x = %d\n", u.x);
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads