Re: Array slices and types



On 20 Sie, 22:45, Adam Beneschan <a...@xxxxxxxxxx> 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
.



Relevant Pages

  • Re: Q: Line_IO
    ... Does this apply to String parameters? ... pragma Elaborate_Body; ... -- - Lines are not longer than internal buffer size. ... subtype Index is Stream_Element_Offset range ...
    (comp.lang.ada)
  • Re: String in Memofeld suchen
    ... Subtype, den deklarierst Du hier, und dann gibt es Funktionen, die geben ... einen Variant mit einem Subtype z.B. String zurück. ... Subtype String ist genau so stark typisiert, ... Kompliziertheit und je Zeile Code ausbezahlt. ...
    (microsoft.public.de.access)
  • Re: ADA Popularity Discussion Request
    ... Positive is a subtype of Integer. ... Should this library use: String, ... support of interface implementation is very rudimental. ... For developing class-wide/generic libraries. ...
    (comp.lang.ada)
  • Re: unsigned type
    ... -- Define a Put routine for String type. ... the subtype even when the range bounds don't actually belong to the ...
    (comp.lang.ada)
  • Re: Array slices and types
    ... type Name is new String (1 .. ... Everything that I can think of (short of copying characters ... subtype Name is String (1 .. ... But I would not declare Name to be a new ...
    (comp.lang.ada)