comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Unclear error message - please help
Date: 08 Oct 2005 19:58:50 -0400
Date: 2005-10-08T19:58:50-04:00	[thread overview]
Message-ID: <wcc64s7ftmt.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 43482077.3434FCF3@alfred-hilscher.de

Alfred Hilscher <SPAM@alfred-hilscher.de> writes:

> Robert A Duff schrieb:
> > 
> > Other ideas:
> > 
> > Don't use Integer all over the place, but instead use
> > different types, to avoid confusion.
> 
> Ok, I tried it, but it seems that a "subtype" is also not the solution:

When I said "different types" I didn't mean "subtypes".

> package spec:
> package Pkg is
> 
>   subtype 
>     Sixteen_Bits is Integer range 0..65535;

This is just a subtype of Integer, not a different type.  To declare
different _types_, you say something like:

    type Apple_Count is range 1..100;
    type Orange_Count is range 1..100;

These are two different types, and different from Integer, too.
Overloading is based on _types_, not subtypes.

It depends on what you're doing, but I suspect Sixteen_Bits is not a
good name for a type.  Name your types after what you're measuring our
counting or indexing or whatever -- not how big they are.

>   procedure Proc (Host : STRING; RC : out Integer; Identifier : in
> Sixteen_Bits := 0);
> 
>   procedure Proc (Host : STRING;
>                  Time_Response : out Integer; RC : out Integer;
>                  Time_Wait : Integer := 10;
>                  Identifier : in Sixteen_Bits := 0);

Think about this: Why are return codes and amounts of time the "same
type"?  And "identifiers"?

> end Pkg;
> 
> program:
> with Text_IO;
> with Ada.Command_Line;  use Ada.Command_Line;
> 
> with Pkg; use Pkg;
> 
> procedure PkgTest is
>   RC : Integer;
> begin
>   if Argument_Count /= 1
>   then
>     Text_IO.Put_Line ("call: PkgTest <ip>");
>     return;
>   end if;
>   
>   Proc (Argument (1), RC, Sixteen_Bits (2507));
                            ^^^^^^^^^^^^^^^^^^^

I think you meant "Sixteen_Bits'(2507)".

That is, a qualified expression, not a type conversion.

>   Text_IO.Put_Line ("RC=" & Integer'Image (RC));
> end PkgTest;
> 
>  
> > Or use two different names, instead of calling both "Proc".
> 
> No, that's not what I want. The advantage of Ada against other languages
> is the overloading: that same things can have the same name(e.g. Put for
> all types, unlike WriteInt, WriteCard ... in Modula).
>  
> > - Bob
> 
> Alfred
> 
> -- 
> -----------------------------------------------------
> To send me mail, please replace "Spam" by "Jedermann"
> -----------------------------------------------------



  parent reply	other threads:[~2005-10-08 23:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-17 21:11 Unclear error message - please help Alfred Hilscher
2005-09-17 21:44 ` Gene
2005-09-17 22:02 ` Ludovic Brenta
2005-09-18  2:32 ` Robert A Duff
2005-10-08 19:39   ` Alfred Hilscher
2005-10-08 20:15     ` Björn Persson
2005-10-09  7:34       ` Martin Krischik
2005-10-08 21:28     ` Dmitry A. Kazakov
2005-10-08 23:58     ` Robert A Duff [this message]
2005-10-09  7:29     ` Martin Krischik
2005-10-09 14:24       ` Robert A Duff
2005-10-09 22:02       ` Brian May
2005-10-10 16:49         ` Martin Krischik
2005-10-10 22:20           ` Brian May
2005-10-11  5:48             ` Martin Dowie
2005-10-11 18:03             ` Martin Krischik
     [not found]         ` <h84lk1tqgofrhgabm8q3sqbb80li6733bh@4ax.com>
2005-10-16  1:10           ` Robert A Duff
replies disabled

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