hello i have a question about incompatible pointer type [modified]
-
i have this code:
type
Symbol = string[8];
SymTab = array[1..1000] of Symbol;
TabPtr = ^SymTab;var
ST: array[1..MaxEntry] of Symbol;
SType: array[1..MaxEntry] of char;132 function Lookup(T: TabPtr; s: string; n: integer): integer;
133 var
134 i: integer;
135 found: Boolean;
136 begin
137 found := false;
138 i := n;
139 while (i > n) and not found do
140 if s = T^[i] then
141 found := true
142 else
143 dec(i);
144 Lookup := i;
145 end;152 function InTable(n: Symbol): Boolean;
153 begin
154 InTable := Lookup(@ST, n, MaxEntry) <> 0;
155 end;when i complier with gpc , it will print this:Tiny10.pas: In function `InTable':
<b>Tiny10.pas:154: error: passing arg 1 of `Lookup' from incompatible pointer type
Tiny10.pas:132: error: routine declaration</b>can you tell me why? actually,i just know C++, i learn pascal for i read a book which use it.
thank youmodified on Tuesday, December 7, 2010 3:53 AM
-
i have this code:
type
Symbol = string[8];
SymTab = array[1..1000] of Symbol;
TabPtr = ^SymTab;var
ST: array[1..MaxEntry] of Symbol;
SType: array[1..MaxEntry] of char;132 function Lookup(T: TabPtr; s: string; n: integer): integer;
133 var
134 i: integer;
135 found: Boolean;
136 begin
137 found := false;
138 i := n;
139 while (i > n) and not found do
140 if s = T^[i] then
141 found := true
142 else
143 dec(i);
144 Lookup := i;
145 end;152 function InTable(n: Symbol): Boolean;
153 begin
154 InTable := Lookup(@ST, n, MaxEntry) <> 0;
155 end;when i complier with gpc , it will print this:Tiny10.pas: In function `InTable':
<b>Tiny10.pas:154: error: passing arg 1 of `Lookup' from incompatible pointer type
Tiny10.pas:132: error: routine declaration</b>can you tell me why? actually,i just know C++, i learn pascal for i read a book which use it.
thank youmodified on Tuesday, December 7, 2010 3:53 AM
Hi, 1. this is not the right forum for this. Your code might be Pascal, it certainly isn't Visual Basic. 2. I don't know the answer, I would however try again without the '@' in line 154 3. yes, I use line numbers to my advantage, and so should you; tell your IDE to show line numbers, look at such details when the compiler or run-time reports problems, and when you post, indicate which line has what line number of interest. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, and update CP Vanity to V2.0 if you haven't already.
-
i have this code:
type
Symbol = string[8];
SymTab = array[1..1000] of Symbol;
TabPtr = ^SymTab;var
ST: array[1..MaxEntry] of Symbol;
SType: array[1..MaxEntry] of char;132 function Lookup(T: TabPtr; s: string; n: integer): integer;
133 var
134 i: integer;
135 found: Boolean;
136 begin
137 found := false;
138 i := n;
139 while (i > n) and not found do
140 if s = T^[i] then
141 found := true
142 else
143 dec(i);
144 Lookup := i;
145 end;152 function InTable(n: Symbol): Boolean;
153 begin
154 InTable := Lookup(@ST, n, MaxEntry) <> 0;
155 end;when i complier with gpc , it will print this:Tiny10.pas: In function `InTable':
<b>Tiny10.pas:154: error: passing arg 1 of `Lookup' from incompatible pointer type
Tiny10.pas:132: error: routine declaration</b>can you tell me why? actually,i just know C++, i learn pascal for i read a book which use it.
thank youmodified on Tuesday, December 7, 2010 3:53 AM
This is Pascal, not VB. Maybe the Delphi forum would have been better for this question. Anyway: ST is declared as array[1..MaxEntry] of Symbol TabPtr is declared as ^SymTab (pointer to SymTab) T parameter in Lookup function is declared as TabPtr -- ^SymTab So, declare ST as SymTab and it should work.
-
This is Pascal, not VB. Maybe the Delphi forum would have been better for this question. Anyway: ST is declared as array[1..MaxEntry] of Symbol TabPtr is declared as ^SymTab (pointer to SymTab) T parameter in Lookup function is declared as TabPtr -- ^SymTab So, declare ST as SymTab and it should work.
thank you.