comp.lang.ada
 help / color / mirror / Atom feed
From: Rob Solomon <usenet@drrob1-noreply.com>
Subject: Re: Why is this not legal
Date: Mon, 28 Sep 2009 22:06:47 -0400
Date: 2009-09-28T22:06:47-04:00	[thread overview]
Message-ID: <5mq2c5haj6hi5e5gm8b397luua3l5fo79u@4ax.com> (raw)
In-Reply-To: 303d304d-8ff1-4d46-af76-88fafeec7e46@b2g2000yqi.googlegroups.com

>On Sep 28, 5:11�pm, Rob Solomon <use...@drrob1-noreply.com> wrote:
>> I am trying to write some simple string manipulations but am getting
>> an error I don't understand.
>>
>> � type WordEntryType is String(1..MaxLineLength);
>>
>> This is flagged as not legal. �GNAT want it to read
>> IS NEW String
>>
>> But that means the type is not a standard string.
>>
>> What am I missing?
>
>The three letters "sub" in front of the keyword "type".
>
>TYPE declarations always create a new type.  SUBTYPE declarations will
>declare an identifier that refers to the same *type*, but puts
>additional constraints on it.  But if you use a SUBTYPE declaration,
>and you declare something of type
>
>  X : WordEntryType;
>
>then X's *type* will be STRING and you can pass it to procedures that
>require a STRING parameter.
>
>If this is still confusing to you, then I'd say you need to go back
>and read some more about Ada's type system.  This is an important
>feature of Ada that distinguishes it from C, Pascal, and possibly
>Modula (I don't know Modula well enough to say), and any decent
>introductory book on Ada should have a good exposition of this
>concept.
>
>                               -- Adam

That worked.  Thanks.

I find it confusing when I need a type vs subtype.  Modula-2 does not
have the subtype concept; it probably could use it though.

And your comment that a subtype adds constraints to a type also helps.

--rob



  reply	other threads:[~2009-09-29  2:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-29  0:11 Why is this not legal Rob Solomon
2009-09-29  0:23 ` Adam Beneschan
2009-09-29  2:06   ` Rob Solomon [this message]
2009-10-01 20:54   ` Keith Thompson
2009-09-30  8:39 ` Martin Krischik
2009-09-30  5:10   ` stefan-lucks
replies disabled

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