This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help with bit-field semantics in C and C++


On Tuesday, August 24, 2004, at 02:40 PM, Gabriel Dos Reis wrote:
| The intent of the standard is not to confuse bool into this...

Huh? Exactly which part of the above quote do you derive that from?

Read the paper that introduced bool into the standard and the standard just before that and review the complete logs of all that was said on the reflector for bool and in the meetings where it was discussed.


If you change the (input) problem, you should expect a different
output.  The enum

enum { foo = 3 } e;

out to be represented by an integer type large enough to represent the
value 3.  Can bool do that? No.  so, the new example you bring does
not bear much relevance to the original example at discussion.

The _original_ example was:


extern "C" void abort(void);

enum E { e = 0x0f };

void test(int n)
{
  enum E x, y;

  x = (E)0x10;
  y = (E)n;

  if (x != y)
    abort ();
}

int main()
{
  test(0x10);
  return 0;
}

which if you squint, you can see it more closely matches my example...

| e = 7;

Ok, I blew that one... I was thinking of a slightly different test case. One that made full use of the full range of the underlying type in a portable program.


T<sizeof (e)> x = 7;
memcpy ((char *)&e, (char *)&x, sizeof (e));

The issue remains the same... Could be good DR material...

Values of type bool are either true or false.42)

Yeah, and I was thinking of:


  42) Using a bool value in ways described by this  International  Stan-
  dard as ``undefined,'' such as by examining the value of an uninitial-
  ized automatic variable, might cause it to behave  as  if  is  neither
  true nor false.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]