From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Noob question: universal_integer type
Date: Sat, 22 May 2010 01:33:02 +0200
Date: 2010-05-22T01:33:02+02:00 [thread overview]
Message-ID: <op.vc2w1ctkule2fv@garhos> (raw)
In-Reply-To: buEJn.4423$Z6.586@edtnps82
Le Sat, 22 May 2010 01:15:19 +0200, Duke Normandin <dukeofperl@ml1.net> a
écrit:
> Coronado's Ada tutorial - Chapt3
>
> [quote]
> The constant 17 is of a very special type defined by Ada as type
> "universal_integer" which can be combined with any of the integer types
> without specific conversion.
> [/quote]
>
> Let me get this right... if I use an undeclared integer in an expression,
> Ada will "deem it" to be a "universal_integer" and not choke at
> compile-time?
On this subject, you may like to read a previous thread named “Integer
questia”.
Here is a Google Group link for conveniance:
http://groups.google.com/group/comp.lang.ada/browse_thread/thread/d9d2bccce5d4fc93#
The key, is that universal integer, is a type like other types you may
defined. Every type integer-like type can be converted to and from
universal integer.
So, yes, the compiler will not complain, because if you have
My_Constant : constant := 1; -- Named number, that is here, universal
integer.
type My_Integer_Type is range 1 .. 9;
My_Entity : My_Integer_Type := My_Constant;
the compiler will not see a contradiction, it will not see the declaration
of a given type which is initialized with a value of a different type, it
will see a literal, which it will automatically convert to the target type.
--
There is even better than a pragma Assert: a SPARK --# check.
next prev parent reply other threads:[~2010-05-21 23:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-21 23:15 Noob question: universal_integer type Duke Normandin
2010-05-21 23:33 ` Yannick Duchêne (Hibou57) [this message]
2010-05-21 23:34 ` Yannick Duchêne (Hibou57)
2010-05-21 23:37 ` Jeffrey R. Carter
2010-05-22 2:04 ` Duke Normandin
2010-05-22 7:16 ` Niklas Holsti
2010-05-22 13:04 ` Duke Normandin
2010-05-22 13:47 ` Dmitry A. Kazakov
2010-05-22 14:51 ` Duke Normandin
2010-05-22 20:08 ` Yannick Duchêne (Hibou57)
2010-05-23 2:28 ` Duke Normandin
2010-05-23 2:36 ` Yannick Duchêne (Hibou57)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox