comp.lang.ada
 help / color / mirror / Atom feed
From: jm21@acmey.gatech.edu (Jim Marks)
Subject: Re: GNAT-Problem '+'-operator with Count
Date: 3 Dec 1994 12:24:11 GMT
Date: 1994-12-03T12:24:11+00:00	[thread overview]
Message-ID: <3bpo1b$771@mordred.gatech.edu> (raw)
In-Reply-To: 3bn74o$go5@tucs6.rz.tu-cottbus.de

Andreas Krohn (ak@informatik.tu-cottbus.de) wrote:
: I have a problem with the '+' operator in GNAT. I have posted the part with
: the error message. Could someone give me a hint, how to solve this
: problem.



:    147.                                                                    
:    148. procedure solve_matrix(source: in matrix;target: in out matrix) is 
:    149.     x,y,i,j:Count;    --akt. Pos. in Matrix                        
:    150.     nachbarn:INTEGER;          --Anzahl der Nachbarn jeder Zelle   
:    151.     a,b:Count;                                                     
:    152.                                                                    

Where is type Count defined?  If it was defined in another package, then
you might not have visibility to the "+" operator for it.  On the other hand,
if it is a subtype of Integer, then I'm not sure what the problem is.

...

:    159.           a:=i+x-2;                                                
:                       |                                                    
:         invalid operand types for operator "+"                             
: z                                                                          
: z   160.                  b:=j+y-2;                                        
:                       |                                                    
:         invalid operand types for operator "+"                             
: z                                                                          
:                                                                            

I tried to reconstruct this using GNAT 1.83 and the Count type defined
in Text_IO.  I had the following code:

with text_IO;
procedure test_plus is
    subtype Count is text_io.count;
    package iio is new text_io.integer_io(count);
    x : count := 5;
    y : count := 6;
    i : count;
begin
    i := x+y-2;         <---- error here
    text_io.put("x = "); iio.put(x); text_io.new_line;
    text_io.put("y = "); iio.put(y); text_io.new_line;
    text_io.put("i = "); iio.put(i); text_io.put_line(" (x+y-2)");
end;

In this code, I get the same error you did at the point indicated.  If,
however, I include renaming declarations for the functions "+" and "-"

    function "+"(left, right : text_io.count) return text_io.count
        renames text_io."+";
    function "-"(left, right : text_io.count) return text_io.count
        renames text_io."-";

then it compiles OK.  Alternatively, if I make the definition of Count
to be a distinct type (not a subtype)

    type Count is new text_io.count;

then I don't need the renaming declarations because the declaration of
type Count includes these functions.

Not knowing where your type (or subtype) Count comes from, I'm not sure
if this is your problem or not.  Still, I hope this helps.


--
************************************************************************
*Jim Marks		 	    |  Georgia Tech Research Institute *
*jim.marks@gtri.gatech.edu	    |  ELSYS/CAD                       *
************************************************************************



  reply	other threads:[~1994-12-03 12:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-12-02 13:23 GNAT-Problem '+'-operator with Count Andreas Krohn
1994-12-03 12:24 ` Jim Marks [this message]
1994-12-05 12:46 ` Joseph Skinner
1994-12-07 22:54   ` Bob Duff
1994-12-08 19:45     ` Jahn Rentmeister
1994-12-09 15:33 ` Robert Dewar
replies disabled

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