From: Duke Normandin on
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?
--
Duke
*** Tolerance becomes a crime, when applied to evil [Thomas Mann] ***

From: Yannick Duchêne (Hibou57) on
Le Sat, 22 May 2010 01:15:19 +0200, Duke Normandin <dukeofperl(a)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.
From: Yannick Duchêne (Hibou57) on
Le Sat, 22 May 2010 01:33:02 +0200, Yannick Duchêne (Hibou57)
<yannick_duchene(a)yahoo.fr> a écrit:
> The key, is that universal integer, is a type like other types you may
Sorry, a word is missing. Please, read “universal integer, is *not* a type
like other types”.
With apologizes.

--
There is even better than a pragma Assert: a SPARK --# check.
From: Jeffrey R. Carter on
Duke Normandin wrote:
>
> 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?

I don't know, and I've been using Ada since 1984. What is "an undeclared integer"?

17 is an integer literal; all integer literals are universal_integer. 17 is not
an undeclared integer.

What the tutorial is trying to get across is that Ada, unlike some languages,
does not have typed numeric literals (see also universal_real). You might
encounter a language in which 10 is a literal of type int and 10L a literal of
long int, for example. In Ada, all integer literals are universal_integer, and
implicitly converted to specific integer types as required.

Partly this makes life easier: you can change the type of a variable and not
have to change all the literals used with that variable; and partly it's pretty
much needed in a language that lets you define your own numeric types.

--
Jeff Carter
"C's solution to this [variable-sized array parameters] has real
problems, and people who are complaining about safety definitely
have a point."
Dennis Ritchie
25
From: Duke Normandin on
On 2010-05-21, Jeffrey R. Carter <spam.jrcarter.not(a)spam.acm.org> wrote:
> Duke Normandin wrote:
>>
>> 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?
>
> I don't know, and I've been using Ada since 1984. What is "an undeclared integer"?
>
> 17 is an integer literal; all integer literals are universal_integer. 17 is not
> an undeclared integer.
>
> What the tutorial is trying to get across is that Ada, unlike some languages,
> does not have typed numeric literals (see also universal_real). You might
> encounter a language in which 10 is a literal of type int and 10L a literal of
> long int, for example. In Ada, all integer literals are universal_integer, and
> implicitly converted to specific integer types as required.
>
> Partly this makes life easier: you can change the type of a variable and not
> have to change all the literals used with that variable; and partly it's pretty
> much needed in a language that lets you define your own numeric types.
>

OK! I got it...
--
Duke
*** Tolerance becomes a crime, when applied to evil [Thomas Mann] ***

 |  Next  |  Last
Pages: 1 2 3
Prev: Ada-bindings for 0mq.
Next: Ada Debian policy plea