comp.lang.ada
 help / color / mirror / Atom feed
From: Eryndlia Mavourneen <eryndlia@gmail.com>
Subject: Gnat's Handling of Record with Address Clause
Date: Thu, 26 Sep 2013 07:23:36 -0700 (PDT)
Date: 2013-09-26T07:23:36-07:00	[thread overview]
Message-ID: <62fd156b-0be2-4465-aeba-287ec9ce22e0@googlegroups.com> (raw)

The following heavily edited code fragment is disallowed by Gnat:

   package body Callback_Pkg is
      Max_Message_Size : constant Natural := 16 * 512;
      subtype My_Message_L_T is Natural range 1 .. Natural (Max_Message_Size);

      type My_Buffer_T (My_Message_L : My_Message_L_T) is
         record
            My_Message_S : String (1 .. My_Message_L);
         end record;

      Local_Buffer_Addr : An_Addr_Type;

      procedure Callback_Proc (Message      : An_Addr_Type;
                               Message_Size : A_Size_Type) is
      begin
         Local_Buffer_Addr := Message;

         Declare_Buffer:
         declare
            Local_Buffer : My_Buffer_T with Address => Local_Buffer_Addr;
         begin
            Put_Line (...);
         end Declare_Buffer;
      end Callback_Proc;
   end Callback_Pkg;

NOTE that type My_Buffer_T, subtype My_Message_L_T, and constant Max_Message_Size are all defined in an external package at top level.  I have placed them here for easy reference.

Gnat tells me:

1) (for Local_Buffer)
   unconstrained subtype not allowed (need initialization)

   provide initial value or explicit discriminant values

   or give default discriminant values for type "My_Buffer_T"

2) (also for Local_Buffer)
   invalid address clause for initialized object "Local_Buffer"

   reference to variable "Local_Buffer_Addr" not allowed (RM 13.1(22))

I can understand (1), and I can initialize the record's discriminant, doing away with this message; however, I do not understand that (2) says the record is initialized, unless it is some kind of default initialization.

RM 13.1(22) says: "An implementation need not support the specification for a representation aspect that contains nonstatic expressions, unless each nonstatic expression is a name that statically denotes a constant declared before the entity."

The overall effect of all this appears to be that Gnat is allowed to disallow a dynamically-determined address for an object.  If this is what is happening here (not a bug in Gnat), then it would seem that any kind of OS work, looping through a kernel linked list, for instance, would not be possible.

A further NOTE:  (1) says truthfully that the immediate definition of Local_Buffer is not initialized; however, that assumption ignores the address clause.  With the address clause, Local_Buffer *is* initialized at the specified address.  Perhaps Gnat's error should be changed to a warning in this case.

Any help here on these issues?

-- Eryndlia (KK1T)

             reply	other threads:[~2013-09-26 14:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-26 14:23 Eryndlia Mavourneen [this message]
2013-09-26 14:48 ` Gnat's Handling of Record with Address Clause Adam Beneschan
2013-09-26 15:05   ` Eryndlia Mavourneen
2013-09-26 15:21     ` Adam Beneschan
2013-09-26 15:09 ` Adam Beneschan
2013-09-26 15:46   ` Eryndlia Mavourneen
2013-09-26 20:00 ` Shark8
2013-09-27 12:55   ` Eryndlia Mavourneen
replies disabled

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