comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Why is this not legal
Date: Mon, 28 Sep 2009 17:23:49 -0700 (PDT)
Date: 2009-09-28T17:23:49-07:00	[thread overview]
Message-ID: <303d304d-8ff1-4d46-af76-88fafeec7e46@b2g2000yqi.googlegroups.com> (raw)
In-Reply-To: 03k2c5lvkk6o9ihd9hbhpnobieoupjg9pc@4ax.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




  reply	other threads:[~2009-09-29  0:23 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 [this message]
2009-09-29  2:06   ` Rob Solomon
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