comp.lang.ada
 help / color / mirror / Atom feed
* Compare these two (sub)type declarations
@ 2006-07-04  9:46 Lance
  2006-07-04 10:25 ` Ludovic Brenta
  2006-07-05 17:42 ` Compare these two (sub)type declarations Martin Krischik
  0 siblings, 2 replies; 5+ messages in thread
From: Lance @ 2006-07-04  9:46 UTC (permalink / raw)


What is the difference between these two declarations?

subtype Foo is Integer;

and

type Bar is new Integer;

In fact, what _is_ the second declaration? Would variables of type Bar
not be allowed in expressions where Integers are expected?


Jerry




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Compare these two (sub)type declarations
  2006-07-04  9:46 Compare these two (sub)type declarations Lance
@ 2006-07-04 10:25 ` Ludovic Brenta
  2006-07-04 20:01   ` Lance
  2006-07-05 17:42 ` Compare these two (sub)type declarations Martin Krischik
  1 sibling, 1 reply; 5+ messages in thread
From: Ludovic Brenta @ 2006-07-04 10:25 UTC (permalink / raw)


Lance writes :
> What is the difference between these two declarations?
>
> subtype Foo is Integer;

Foo is a subtype. It is compatible with Integer and with all other
subtypes of Integer such as Natural and Positive, i.e. you can convert
implicitly between all these subtypes. The compiler inserts range
checks where appropriate.

> and
>
> type Bar is new Integer;
>
> In fact, what _is_ the second declaration? Would variables of type Bar
> not be allowed in expressions where Integers are expected?

Bar is a derived type. It is not compatible with Integer, or with any
subtype of Integer, so the compiler would reject a program that passes
a Bar to a subprogram that expects an Integer. You can, however,
convert _explicitly_ between Bar and Integer, just like between any two
numeric types; the compiler inserts range checks as appropriate.

HTH
 
> Jerry

Is it Lance, or Jerry now?

-- 
Ludovic Brenta.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Compare these two (sub)type declarations
  2006-07-04 10:25 ` Ludovic Brenta
@ 2006-07-04 20:01   ` Lance
  2006-07-04 21:13     ` spam countermeasures (was: Compare these two (sub)type declarations) Björn Persson
  0 siblings, 1 reply; 5+ messages in thread
From: Lance @ 2006-07-04 20:01 UTC (permalink / raw)



Ludovic Brenta wrote:
> Lance writes :
> > What is the difference between these two declarations?
> >
> > subtype Foo is Integer;
>
> Foo is a subtype. It is compatible with Integer and with all other
> subtypes of Integer such as Natural and Positive, i.e. you can convert
> implicitly between all these subtypes. The compiler inserts range
> checks where appropriate.
>
> > and
> >
> > type Bar is new Integer;
> >
> > In fact, what _is_ the second declaration? Would variables of type Bar
> > not be allowed in expressions where Integers are expected?
>
> Bar is a derived type. It is not compatible with Integer, or with any
> subtype of Integer, so the compiler would reject a program that passes
> a Bar to a subprogram that expects an Integer. You can, however,
> convert _explicitly_ between Bar and Integer, just like between any two
> numeric types; the compiler inserts range checks as appropriate.
>
> HTH
>
> > Jerry
>
> Is it Lance, or Jerry now?
>

My name is Jerry B a u c k. I use the lanceboyle address for mailing
lists for spam control reasons (lance boil is a joke in English) and to
keep from polluting my "real namespace" on the internet. I always sign
as Jerry but surprisingly (to me), people usually reply to "Lance." I
live in Tempe, Arizona, USA where I am self-employed.

Thanks for your informative reply.
> -- 
> Ludovic Brenta.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* spam countermeasures (was: Compare these two (sub)type declarations)
  2006-07-04 20:01   ` Lance
@ 2006-07-04 21:13     ` Björn Persson
  0 siblings, 0 replies; 5+ messages in thread
From: Björn Persson @ 2006-07-04 21:13 UTC (permalink / raw)


Lance wrote:
> My name is Jerry B a u c k. I use the lanceboyle address for mailing
> lists for spam control reasons (lance boil is a joke in English) and to
> keep from polluting my "real namespace" on the internet.

Then I'd recommend that you write "Jerry <lanceboyle@qwest.net>" in the 
"From:" field. You don't need to use a false name. Only the email 
address needs to be false to avoid spam.

> I always sign
> as Jerry but surprisingly (to me), people usually reply to "Lance."

That doesn't surprise me at all. You have in effect introduced yourself 
as "Lance".

-- 
Bj�rn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Compare these two (sub)type declarations
  2006-07-04  9:46 Compare these two (sub)type declarations Lance
  2006-07-04 10:25 ` Ludovic Brenta
@ 2006-07-05 17:42 ` Martin Krischik
  1 sibling, 0 replies; 5+ messages in thread
From: Martin Krischik @ 2006-07-05 17:42 UTC (permalink / raw)


Lance wrote:

> What is the difference between these two declarations?
> 
> subtype Foo is Integer;
> 
> and
> 
> type Bar is new Integer;
> 
> In fact, what _is_ the second declaration? Would variables of type Bar
> not be allowed in expressions where Integers are expected?

Others have given you some hints. If you want the full story:

http://en.wikibooks.org/wiki/Ada_Programming/Type_System

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-07-05 17:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-04  9:46 Compare these two (sub)type declarations Lance
2006-07-04 10:25 ` Ludovic Brenta
2006-07-04 20:01   ` Lance
2006-07-04 21:13     ` spam countermeasures (was: Compare these two (sub)type declarations) Björn Persson
2006-07-05 17:42 ` Compare these two (sub)type declarations Martin Krischik

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