comp.lang.ada
 help / color / mirror / Atom feed
From: Serge Robyns <serge.robyns@gmail.com>
Subject: Bounded String question
Date: Tue, 10 Nov 2015 14:00:02 -0800 (PST)
Date: 2015-11-10T14:00:02-08:00	[thread overview]
Message-ID: <7ba56b33-28d4-42d2-8b9b-5ad9f5beab8b@googlegroups.com> (raw)

I'm trying to use bounded strings and I'm facing some issues when I'm trying to use pragma preelaborate in my package.

I'm using bounded strings to store some text data with an upper limit in size.  I've been a little lazy and I'm reusing the same package for different "types".  But I do want to have the different types to be different, so that they cannot be assigned to each other for example.

package Test is
   -- pragma Preelaborate;
   package P_Strings is new Ada.Strings.Bounded.Generic_Bounded_Length (20);

   type T_Client_Name is new P_Strings.Bounded_String;
   type T_Account_Name is new P_Strings.Bounded_String;

....

   No_Client_Name : constant T_Client_Name;
   No_Account_Name : constant T_Account_Name;
...
private
   No_Client_Name : constant T_Client_Name := T_Client_Name (P_Strings.Null_Bounded_String);
   No_Account_Name : constant T_Account_Name := T_Account_Name (P_Strings.Null_Bounded_String);
...

Everything works fine as long as I don't want to use the pragma preelaborate.

When compiling with pragma preelaborate I get the following errors.
non-static constant in preelaborated unit
static expression must have scalar or string type (RM 4.9(2))

I've been trying to find solutions and so far the only one that seems not to complain is when I'm create subtypes and using renames to rename P_Strings.Null_Bounded_String as for example:
subtype T_Client_Name is P_Strings.Bounded_String;
No_Client_Name : T_Client_Name renames P_Strings.Null_Bounded_String; 

However this is defeating my initial purpose of using types.  Because now I can mix T_Client_Name and T_Account_Name, which is now "legal" but makes no sense in my application.

I've been trying to use pragma Preelaborable_Initialization (T_Client_Name) but this seems not to solve it.

Maybe I'm using bounded strings completely wrong.

Some advise is most welcome.


             reply	other threads:[~2015-11-10 22:00 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-10 22:00 Serge Robyns [this message]
2015-11-11  0:48 ` Bounded String question Bob Duff
2015-11-11  2:01   ` Jeffrey R. Carter
2015-11-11 15:34     ` Bob Duff
2015-11-11 17:36       ` Jeffrey R. Carter
2015-11-11 19:22         ` Bob Duff
2016-03-06 18:59       ` Xavier Petit
2016-03-07 23:16         ` Randy Brukardt
2016-03-08  0:08           ` Jeffrey R. Carter
2016-03-09  1:18             ` Randy Brukardt
2015-11-11 10:52   ` Serge Robyns
2015-11-11 13:43     ` Serge Robyns
2015-11-11 14:32       ` brbarkstrom
2015-11-11 16:08         ` Serge Robyns
2015-11-11 17:27       ` Jeffrey R. Carter
2015-11-11 20:06         ` Serge Robyns
2015-11-11 20:23           ` AdaMagica
2015-11-11 20:27             ` AdaMagica
2015-11-11 20:32             ` Serge Robyns
2015-11-11 20:40               ` AdaMagica
2015-11-12 17:31                 ` Serge Robyns
2015-11-12 19:10                   ` AdaMagica
2015-11-12 21:29                     ` Randy Brukardt
2015-11-12 18:03                 ` G.B.
2015-11-12 18:13                   ` Serge Robyns
2015-11-12 18:14                     ` Serge Robyns
2015-11-12 19:37                   ` Randy Brukardt
2015-11-11 20:42           ` Jeffrey R. Carter
2015-11-12 16:59             ` Serge Robyns
2015-11-12 18:39               ` Jeffrey R. Carter
2015-11-12 21:19                 ` Randy Brukardt
2015-11-12 21:27               ` Randy Brukardt
2015-11-12 22:32                 ` Jeffrey R. Carter
2015-11-13  0:07                   ` Randy Brukardt
2015-11-13  1:01                     ` Jeffrey R. Carter
2015-11-11 15:41     ` Bob Duff
replies disabled

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