From: Juanma Barranquero <lektu@terra.es>
Subject: Assigning the value of a deferred constant?
Date: Mon, 17 Sep 2001 09:53:03 +0200
Date: 2001-09-17T09:53:03+02:00 [thread overview]
Message-ID: <d7abqt09p6i75u5nf014dbge4o11a0534r@4ax.com> (raw)
In-Reply-To: lq9bqtgt5kj60avgvsb9nlmla9hpi2q4ka@4ax.com
On Mon, 17 Sep 2001 09:37:43 +0200, Juanma Barranquero
<lektu@terra.es> wrote:
>More or less. I've been doing:
>
> type Byte_Order is (Little_Endian, Big_Endian);
>
> Default_Byte_Order : Byte_Order;
And vaguely related: Is there any way to declare a deferred constant
and assign its value in the body of the declaring package, during
elaboration? Something like:
package Test is
pragma Elaborate_Body;
type Byte_Order is (Little_Endian, Big_Endian);
Default_Byte_Order : constant Byte_Order;
private
Machine_Order : Byte_Order := Big_Endian;
Default_Byte_Order : constant Byte_Order := Machine_Order;
for Default_Byte_Order'Address use Machine_Order'Address;
end Test;
with Unchecked_Conversion;
package body Test is
type Word is mod 2 ** 32;
subtype Chr4 is String (1..4);
function UC is new Unchecked_Conversion(Word, Chr4);
Test_Word : constant Word := 16#33323130#;
Test_Chr4 : constant Chr4 := "0123";
begin
if UC(Test_Word) = Test_Chr4 then
Machine_Order := Little_Endian;
else
Machine_Order := Big_Endian;
end if;
end Test;
That's not working (on Windows, with GNAT 3.13p), but I don't know if
it should or shouldn't :(
I know I could have different bodies for different architectures, or
just substitute a function for the deferrent constant, doing instead:
function Default_Byte_Order returns Byte_Order;
pragma Inline(Default_Byte_Order);
or something similar. But the question remains: Is there an easy
and/or portable way to have a public constant view of a private
variable?
Thanks,
/L/e/k/t/u
next prev parent reply other threads:[~2001-09-17 7:53 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-15 19:36 Access types and classwide programming chris.danx
2001-09-15 20:28 ` chris.danx
2001-09-15 23:42 ` [Different Topic] Endianess? chris.danx
2001-09-16 6:22 ` Jeffrey Carter
2001-09-17 7:37 ` Juanma Barranquero
2001-09-17 7:53 ` Juanma Barranquero [this message]
2001-09-17 14:04 ` Assigning the value of a deferred constant? Ted Dennison
2001-09-17 14:36 ` Juanma Barranquero
2001-09-17 17:36 ` tmoran
2001-09-18 8:16 ` Juanma Barranquero
2001-09-18 18:40 ` Richard Riehle
2001-09-19 2:07 ` Vincent Marciante
2001-09-19 7:39 ` Juanma Barranquero
2001-09-16 6:19 ` Access types and classwide programming Jeffrey Carter
2001-09-16 13:37 ` chris.danx
2001-09-16 16:49 ` Jeffrey Carter
2001-09-16 18:24 ` David C. Hoos, Sr.
2001-09-17 6:15 ` Jeffrey Carter
2001-09-17 4:57 ` tmoran
2001-09-17 14:16 ` Ted Dennison
2001-09-16 9:32 ` tmoran
2001-09-17 9:41 ` John McCabe
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox