* GNAT-Problem '+'-operator with Count @ 1994-12-02 13:23 Andreas Krohn 1994-12-03 12:24 ` Jim Marks ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Andreas Krohn @ 1994-12-02 13:23 UTC (permalink / raw) 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. 153. begin 154. for i in feldmin..feldmax loop 155. for j in feldmin..feldmax loop 156. nachbarn:=0; --neue Zelle 0 setzen 157. for x in 1..3 loop --nachbarn ermitteln 158. for y in 1..3 loop 159. a:=i+x-2; | invalid operand types for operator "+" z z 160. b:=j+y-2; | invalid operand types for operator "+" z z 161. if source(a,b)=TRUE then nachbarn:=nachbarn+1; 162. end if; 163. end loop; ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GNAT-Problem '+'-operator with Count 1994-12-02 13:23 GNAT-Problem '+'-operator with Count Andreas Krohn @ 1994-12-03 12:24 ` Jim Marks 1994-12-05 12:46 ` Joseph Skinner 1994-12-09 15:33 ` Robert Dewar 2 siblings, 0 replies; 6+ messages in thread From: Jim Marks @ 1994-12-03 12:24 UTC (permalink / raw) 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 * ************************************************************************ ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GNAT-Problem '+'-operator with Count 1994-12-02 13:23 GNAT-Problem '+'-operator with Count Andreas Krohn 1994-12-03 12:24 ` Jim Marks @ 1994-12-05 12:46 ` Joseph Skinner 1994-12-07 22:54 ` Bob Duff 1994-12-09 15:33 ` Robert Dewar 2 siblings, 1 reply; 6+ messages in thread From: Joseph Skinner @ 1994-12-05 12:46 UTC (permalink / raw) In article <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. > 153. begin > 154. for i in feldmin..feldmax loop > 155. for j in feldmin..feldmax loop > 156. nachbarn:=0; --neue Zelle 0 setzen > 157. for x in 1..3 loop --nachbarn ermitteln > 158. for y in 1..3 loop > 159. a:=i+x-2; > | > invalid operand types for operator "+" >z >z 160. b:=j+y-2; > | > invalid operand types for operator "+" >z >z 161. if source(a,b)=TRUE then nachbarn:=nachbarn+1; > 162. end if; > 163. end loop; > At a guess the problem is that the definitions for '+' is not visible to the program. Check out your with and use statements to make sure that the definition is visible. On the other hand I may be spouting BS and I'm sure that someone else will tell me if I am. Joe -- =============================================================================== Joseph Skinner | Invercargill usenet: joe@jsnode.equinox.gen.nz | New Zealand There is no such thing as a wizard who minds his own business - Berengis the Black Court Mage to the Earl Caeline ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GNAT-Problem '+'-operator with Count 1994-12-05 12:46 ` Joseph Skinner @ 1994-12-07 22:54 ` Bob Duff 1994-12-08 19:45 ` Jahn Rentmeister 0 siblings, 1 reply; 6+ messages in thread From: Bob Duff @ 1994-12-07 22:54 UTC (permalink / raw) In article <2ee30bbc.4a534e4f4445@jsnode.equinox.gen.nz>, Joseph Skinner <joe@jsnode.equinox.gen.nz> wrote: >In article <3bn74o$go5@tucs6.rz.tu-cottbus.de>, >Andreas Krohn <ak@informatik.tu-cottbus.de> wrote: >> 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. >> 153. begin >> 154. for i in feldmin..feldmax loop >> 155. for j in feldmin..feldmax loop >> 156. nachbarn:=0; --neue Zelle 0 setzen >> 157. for x in 1..3 loop --nachbarn ermitteln >> 158. for y in 1..3 loop >> 159. a:=i+x-2; >> | >> invalid operand types for operator "+" >>z >>z 160. b:=j+y-2; >> | >> invalid operand types for operator "+" >>z >>z 161. if source(a,b)=TRUE then nachbarn:=nachbarn+1; >> 162. end if; >> 163. end loop; The program fragment doesn't show enough to be sure. In particular, what type are feldmin and feldmax? This type will be used as the type of i and j. However, x and y are of type Integer, since there's a special rule saying that if the bounds are universal_integer (e.g. literals), then it uses Integer. So if feldmin and feldmax are not of type Integer, then you've got a type mismatch. If that's the problem, try this: for x in Whatever_Type_It_Is range 1..3 loop ... I've gotten into the habit of *always* giving the type name in a for loop, since I think the default-to-Integer rule confuses things, and anyway it makes the code more readable. >At a guess the problem is that the definitions for '+' is not visible to >the program. Check out your with and use statements to make sure that >the definition is visible. > >On the other hand I may be spouting BS and I'm sure that someone else >will tell me if I am. Hard to say. My answer's a guess, too. Anyway, in an extremely polite forum such as this, who would ever accuse anyone of "spouting BS"? Instead, I respectfully submit that my guess is more likely correct than yours. ;-) - Bob -- Bob Duff bobduff@inmet.com Oak Tree Software, Inc. Ada 9X Mapping/Revision Team (Intermetrics, Inc.) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GNAT-Problem '+'-operator with Count 1994-12-07 22:54 ` Bob Duff @ 1994-12-08 19:45 ` Jahn Rentmeister 0 siblings, 0 replies; 6+ messages in thread From: Jahn Rentmeister @ 1994-12-08 19:45 UTC (permalink / raw) Bob Duff (bobduff@dsd.camb.inmet.com) wrote: : >Andreas Krohn <ak@informatik.tu-cottbus.de> wrote: : >> 148. procedure solve_matrix(source: in matrix;target: in out matrix) is : >> 149. x,y,i,j:Count; --akt. Pos. in Matrix : >> 157. for x in 1..3 loop --nachbarn ermitteln : >> 158. for y in 1..3 loop : Hard to say. My answer's a guess, too. Anyway, in an extremely polite : forum such as this, who would ever accuse anyone of "spouting BS"? : Instead, I respectfully submit that my guess is more likely correct than : yours. ;-) Given that x and y are declared twice (once in the declarative part as Count and once implicitly in the loop as integer) you might actually be right - but who can be sure? -Jahn -- Those who can, do. Those who can't, try. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: GNAT-Problem '+'-operator with Count 1994-12-02 13:23 GNAT-Problem '+'-operator with Count Andreas Krohn 1994-12-03 12:24 ` Jim Marks 1994-12-05 12:46 ` Joseph Skinner @ 1994-12-09 15:33 ` Robert Dewar 2 siblings, 0 replies; 6+ messages in thread From: Robert Dewar @ 1994-12-09 15:33 UTC (permalink / raw) it is either a bug in GNAT or a bug in your program, and it is impossible to tell which without the full sources. If you want help from the GNAT group, please send full sources to gnat-report@cs.nyu.edu! ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1994-12-09 15:33 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1994-12-02 13:23 GNAT-Problem '+'-operator with Count Andreas Krohn 1994-12-03 12:24 ` Jim Marks 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox