comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Record initialisation question
Date: Thu, 14 Jan 2021 08:53:35 -0800 (PST)	[thread overview]
Message-ID: <1064b0e8-2486-42be-a52d-1b3bc0bfd65en@googlegroups.com> (raw)
In-Reply-To: <i6b2ltFcg4hU1@mid.individual.net>

Another option, which IIUC should work within the constraints, being Pure:

With
Ada.Unchecked_Conversion,
System;

Package Example with Pure is
    
    Type Address_Stub is null record
      with Size => Standard'Address_Size, Warnings => Off;
    Function Convert(Input : System.Address) return Address_Stub;
    
    Type Stub is null record with Size => 8, Warnings => Off;
    Type Static_Record is record
        Reserved_1 : Stub;
        X, Y       : Integer;
        Self       : Address_Stub;
    end record;
    
    Generic
        Location : System.Address;
    Package Based is
        
        Function Create( X, Y : Integer ) return Static_Record;
    Private
        Function Create( X, Y : Integer ) return Static_Record is
          (Self => Convert( Location ), Reserved_1 => (null record),
           X => X, Y => Y
          );
    End Based;
    
    
Private
    Use System, Ada;
    
    Function Address_Conversion is new Unchecked_Conversion(
       Source => Address,
       Target => Address_Stub
      );
    Function Convert(Input : System.Address) return Address_Stub
      renames Address_Conversion;
End Example;

-- Usage should be something like:
Object_Address : Constant System.Address := (<>);
Package Object_Basis is new Example.Based( Object_Address );
Object : Example.Static_Record := Object_Basis.Create( Params => <> );
For Object'Address use Object'Address;

Sorry but I haven't done much in the way of microcontrolers, so this is best-guess on my part. The restrictions of Pure *should* comport with the restrictions you have though, again IIUC.

  reply	other threads:[~2021-01-14 16:53 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-09  9:30 Record initialisation question DrPi
2021-01-09 10:46 ` Dmitry A. Kazakov
2021-01-10 16:41   ` DrPi
2021-01-11 21:48     ` Shark8
2021-01-12 11:38       ` Simon Wright
2021-01-12 15:01         ` Shark8
2021-01-14 21:32           ` Simon Wright
2021-01-14 23:12             ` Shark8
2021-01-14 12:58       ` DrPi
2021-01-17 17:03   ` DrPi
2021-01-17 23:55     ` Shark8
2021-01-18 20:02       ` DrPi
2021-01-19  5:50         ` Randy Brukardt
2021-01-09 15:44 ` Niklas Holsti
2021-01-10 16:53   ` DrPi
2021-01-10 19:30     ` Niklas Holsti
2021-01-10 21:27       ` DrPi
2021-01-10 22:14         ` Niklas Holsti
2021-01-11 17:46           ` DrPi
2021-01-11 20:58             ` Niklas Holsti
2021-01-14 13:07               ` DrPi
2021-01-14 13:36                 ` AdaMagica
2021-01-14 14:07                 ` Jeffrey R. Carter
2021-01-14 14:09                   ` Jeffrey R. Carter
2021-01-14 14:27                 ` Niklas Holsti
2021-01-14 16:53                   ` Shark8 [this message]
2021-01-15  7:50                     ` DrPi
2021-01-15 18:15                       ` Shark8
2021-01-16 10:28                         ` DrPi
2021-01-14 16:59                   ` Paul Rubin
2021-01-15  7:49                   ` DrPi
2021-01-17 17:08 ` DrPi
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox