Possible way to do bitfields that may have not been considered

So, I know that this topic has been discussed many times before, but I'm wondering if this route has been considered by anyone.

We all know that C supports bitfields but that it doesn't specify the ordering of them. But Ada also supports bitfields. This is accomplished via record layouts as specified in subclause 13.5. The specific sections of that subclause that we'd be concerned with are Record Representation Clauses (13.5.1) and Bit Ordering (13.5.3). Ada's syntax for record representation clauses is as follows:

record_representation_clause ::= 
    for first_subtype_local_name use
      record [mod_clause]
      end record;

component_clause ::= 
    component_local_name at position range first_bit .. last_bit;

position ::= static_expression

first_bit ::= static_simple_expression

last_bit ::= static_simple_expression

mod_clause ::= at mod static_expression;

This syntax doesn't work for Rust, but since the storage unit size is not the same as the size of a word on (to my knowledge) any processor architecture, the bit ordering in par. 5 of 13.5.3 is not implementation-defined, and therefore can be specified explicitly. So, for structs, why not model the internal structure after the way ada does it? I'm not really sure how to bend the syntax, though -- I thought about using where to specify bit ranges (maybe something like where bit<0>) to avoid adding new keywords if possible. But I was just wondering if this had ever been considered? I know that Rust has been looking at Ada for inspiration for a lot of things, or at least it has in the past, so I thought about maybe doing that again, since Ada is quite a versatile language, even if (sadly) not many people use it anymore.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.