Topic: Defect Report: Integral promotions on bit-fields


Author: Marvin Sielenkemper <sielenk@gmx.de>
Date: Fri, 27 Jul 2001 09:33:11 GMT
Raw View
Kiril Avdeiv wrote:
>
> [ Forwarded to C++ Committeee. -sdc ]
>
> Paragraph 3 of section 4.5 [conv.prom] contains a statement saying
> that if a bit-field is larger than int or unsigned int, no integral
> promotions apply to it. This phrase needs further clarification, as it
> is hardly possible to fugure out what it means. See below.
>
> Assuming a machine with a size of general-purpose register equal 32
> bits (where a byte takes up 8 bits) and a C++ implementation where an
> int is 32 bits and a long is 64 bits. And the following snippet of
> code:
>
> struct ExternalInterface {
>   long field1:36, field2:28;
> };
>
> int main() {
>   ExternalInterface  myinstance = { 0x100000001L, 0x12,};
>   if(myinstance.field1 < 0x100000002L) { //do something }
> }
>
> Does the standard prohibit the implementation from promoting field1's
> value into two general purpose registers? [...]

The standard doesn't have a notion of 'general purpose register'.
But I understand the problem.
There is an integral conversion defined (4.7-3) for this case.
It's just not called integral promotion because long int values are
deliberately (see below) omitted in 4.5.

IMO, 'integral promotion' is defined by the standard, because most
implementations are based on some kind of register machine and the
type int is supposed to reflect the register 'type'.
An integral promotion can thus be implemented as the atomic action of
loading a register.

Operations on long int values may be far more complex, they might even
invoke calls to runtime support functions.
The machine stated above might have only one accumulator register of
32 bits ...


Marvin H. Sielenkemper

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: kavdeiv@mail.ru (Kiril Avdeiv)
Date: 25 Jul 2001 05:36:48 GMT
Raw View
[ Forwarded to C++ Committeee. -sdc ]

Paragraph 3 of section 4.5 [conv.prom] contains a statement saying
that if a bit-field is larger than int or unsigned int, no integral
promotions apply to it. This phrase needs further clarification, as it
is hardly possible to fugure out what it means. See below.

Assuming a machine with a size of general-purpose register equal 32
bits (where a byte takes up 8 bits) and a C++ implementation where an
int is 32 bits and a long is 64 bits. And the following snippet of
code:

struct ExternalInterface {
  long field1:36, field2:28;
};

int main() {
  ExternalInterface  myinstance = { 0x100000001L, 0x12,};
  if(myinstance.field1 < 0x100000002L) { //do something }
}

Does the standard prohibit the implementation from promoting field1's
value into two general purpose registers? And imposes a burden of
using shift machine instructions to work with the field's value? What
else could that phrase mean?

Either alternative is implementation specific, so I don't understand
why the phrase "If the bit-field is larger yet, no integral promotions
apply to it" made it to the standard.

Thanx
Kiril



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]