second draft: add Bitfields to D

Walter Bright newshound2 at digitalmars.com
Mon May 6 07:14:54 UTC 2024


On 5/5/2024 2:08 AM, Timon Gehr wrote:
> GCC 11.4.0, clang 14.0.0:
> 
> ```c
> #include <stdio.h>
> struct __attribute__((packed)) S{
>      long long x:8;
> };
> int main(){
>      printf("%ld\n",sizeof(long long)); // 8
>      printf("%ld\n",sizeof(struct S)); // 1
> }
> ```

The sizeof there, in both cases, is giving the size in bytes of the memory 
object the field is a subset of.


> Maybe at least redefine `.sizeof` to give the size of the underlying storage 
> unit for a bitfield.

That's what it's doing in the example.

BTW, I didn't implement packed bitfields in ImportC. It never occurred to me :-/ 
I suppose it should get a bugzilla issue.

https://issues.dlang.org/show_bug.cgi?id=24538


More information about the dip.development mailing list