[fpc-devel] Re: strange error with arm compiler whencompiling-running this code

Yury Sidorov jura at cp-lab.com
Wed Mar 14 21:48:58 CET 2007


From: "Roozbeh GHolizadeh" <roozbehid at yahoo.com>
> well i am really going crazy.these c codes run ok
> -------------------testpchar.c-------------
> typedef struct
> {
>  char *name;
> }
> namestruct;
> 
> namestruct namestructs[1] = 
> {{"12345"}};  
> 
> 
> int findname (char *s)
> {
>  
> return namestructs[0].name[1];
> }
> ----------------main.c------------------
> int main (int argc, char *argv[])
> {
> char s[]="s";
> printf("start\n");
> printf("%d \n",findname(s));
> printf("end\n");
> return 0;
> }
> 
> output is :
> 
> start
> 50
> end
> 
> and now the pascal code
> {$apptype console}
> {$link testpchar.o}
> 
> function findname (s : PChar) :
> cardinal;cdecl;external name 'findname';
> 
> var
> s:shortstring;
> begin
> writeln('start');
> s:='s'#0#1;
> writeln(findname(@s[1]));
> writeln('end');
> end.
> 
> 
> output is
> start
> runtime error 216
> 
> and if i change the c code into
> .
> .
> return namestructs[2].name[1];//ie change 0 into 2
> .
> .
> 
> output is
> start
> 50
> end
> 
> 
> which is ok!
> so whay exactly is wrong here,fpc compiler or evc compiler?!

Use debugger to find what instruction and where causes runtime error 216 which is access violation.

Yury.



More information about the fpc-devel mailing list