comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Array slices and types
Date: Thu, 21 Aug 2008 14:16:20 -0700 (PDT)
Date: 2008-08-21T14:16:20-07:00	[thread overview]
Message-ID: <48b63de7-5990-4612-8129-83d9262587f4@d77g2000hsb.googlegroups.com> (raw)
In-Reply-To: 1eb141ff-82f8-4969-a525-5e931419d631@1g2000pre.googlegroups.com

On 20 Sie, 22:45, Adam Beneschan <a...@irvine.com> wrote:

> Do you really need a new *type*, as opposed to:
>
>    subtype Name is String (1 .. 10);
>
> ???

Good question. If I make it a subtype, then I have no protection
against mixing First_Name with Device_Name with File_Name with
Signal_Name with Any_Other_Name - and that would defeat the whole
purpose of defining them.

Consider:

declare

   subtype First_Name is String (1 .. 4);
   subtype Device_Name is String (1 .. 4);

   Someone : First_Name := "Adam";
   Something : Device_Name := "usb1";

begin
   Someone := Something;  -- oops
end;

That's why I was thinking about distinct types. I'm OK with type casts
when assigning them from regular String.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



  reply	other threads:[~2008-08-21 21:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-20 14:51 Array slices and types Maciej Sobczak
2008-08-20 15:26 ` Niklas Holsti
2008-08-20 15:46 ` Dmitry A. Kazakov
2008-08-20 18:52   ` Niklas Holsti
2008-08-20 20:01     ` Simon Wright
2008-08-21  5:26       ` Niklas Holsti
2008-08-21  8:53         ` Dmitry A. Kazakov
2008-08-21 14:44           ` Adam Beneschan
2008-08-21 15:46             ` Dmitry A. Kazakov
2008-08-22  4:30             ` Randy Brukardt
2008-08-20 17:47 ` stefan-lucks
2008-08-20 17:51   ` stefan-lucks
2008-08-20 20:45 ` Adam Beneschan
2008-08-21 21:16   ` Maciej Sobczak [this message]
2008-08-23  2:50 ` Steve
replies disabled

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