News for hackers. Stuff that matters.
Re:The Lost Art of Structure Packing (2018) by 0xDEEPFAC on Monday April 27, 2020 @01:22PM (#22997842)
Looks like what he really wants is to use Ada which has had much better support for low-level programming than C.

Example:

Word : constant := 4; -- storage element is byte, 4 bytes per word

type State is (A,M,W,P); type Mode is (Fix, Dec, Exp, Signif);

type Byte_Mask is array (0..7) of Boolean; type State_Mask is array (State) of Boolean; type Mode_Mask is array (Mode) of Boolean;

type Program_Status_Word is record System_Mask : Byte_Mask;

       Protection_Key     : Integer range 0 .. 3;

       Machine_State      : State_Mask;

       Interrupt_Cause    : Interruption_Code;

       Ilc                : Integer range 0 .. 3;

       Cc                 : Integer range 0 .. 3;

       Program_Mask       : Mode_Mask;

       Inst_Address       : Address;

 end record;

 for Program_Status_Word use

   record
       System_Mask      at 0*Word range 0  .. 7;

       Protection_Key   at 0*Word range 10 .. 11; -- bits 8,9 unused

       Machine_State    at 0*Word range 12 .. 15;

       Interrupt_Cause  at 0*Word range 16 .. 31;

       Ilc              at 1*Word range 0  .. 1;  -- second word

       Cc               at 1*Word range 2  .. 3;

       Program_Mask     at 1*Word range 4  .. 7;

       Inst_Address     at 1*Word range 8  .. 31;

   end record;

 for Program_Status_Word'Size use 8*System.Storage_Unit;

 for Program_Status_Word'Alignment use 8;

More info: https://www.adaic.org/resources/add_content/standards/05aarm...
Re:The Lost Art of Structure Packing (2018) by samatman on Monday April 27, 2020 @05:44PM (#23000473)
For all its somewhat fussy verbosity, Ada really impresses me every time this sort of thing comes up.

I keep hoping the Zig developer will do a deep dive on Ada and bring over more of this kind of precise control. A language where I have this kind of control over layout, but can still spell `end record;` as `}`, is ideal for some projects I have in mind.

Re:The Lost Art of Structure Packing (2018) by SlowRobotAhead on Monday April 27, 2020 @02:02PM (#22998257)
I use C for embedded. I do the “lost art” of structure packing all the time. I don’t want ada.

I’m not sure why “use a different language” is such a common reply to any language specific discussion.