There seems to be subtle inconsistancies with accessing 'C' Arrays from PASCAL. I am concerned that array variables need to be treated differently than array parameters. Basically, variables need to be declared as arrays and parameters need to be declared as pointers to arrays.
I would have thought that if I declared a 'C' array variable to be a pointer, and a function parameter to be a pointer, that when I pass the variable to the function, PASCAL should pass a pointer. However, this is not the case for 'C' array variables.
The following code fragments demonstrate this: <<TEST.C>>
int carray[5] = {0x01010101,0x02020202,0x03030303,0x04040404,0x05050505}; int c1array[5] = {0x01010101,0x02020202,0x03030303,0x04040404,0x05050505};
void print_array(int *arr) { int i;
for (i=0; i < 5; i++) printf("%8X\n",arr[i]); }
<<ARRTEST.PAS>>
program ArrTest;
{$L test.c}
type CCARRAY = array[0..4] of Integer; CCARRAY_PTR = ^CCARRAY; var carray : __asmname__ 'carray' CCARRAY_PTR; c1array : __asmname__ 'c1array' CCARRAY; pas_arr : CCARRAY value ($01010101,$02020202,$03030303,$04040404,$05050505); p : CCARRAY_PTR;
procedure print_array(arr : CCARRAY_PTR); AsmName 'print_array';
begin p := &pas_arr; WRITELN('c array'); print_array(&carray); {this & seems wrong} WRITELN('c1 array'); print_array(&c1array); WRITELN('pascal array'); print_array(p); WRITELN('pascal array'); print_array(&pas_arr); end.
PASCAL treats 'C' arrays the same, irrespective of whether they are declared as a plain array or as a pointer to an array. The & operator is required to pass 'C' arrays to 'C' subroutines.
Alternatively, in my PASCAL declarations of 'C' functions, I could declare all 'C' array parameters to be VAR parameters. But this just doesn't seem right.
On another matter, I downloaded the latest binary of GPC (gpc-19980830.i386-djgppv201.zip). Now, I keep getting a linker error about crt0.o. How do I overcome this?
thanks Russell
Thamm, Russell wrote:
[...] I would have thought that if I declared a 'C' array variable to be a pointer, and a function parameter to be a pointer, that when I pass the variable to the function, PASCAL should pass a pointer. However, this is not the case for 'C' array variables.
The problem lies in the C, not in the Pascal code:
int c1array[5] = {0x01010101,0x02020202,0x03030303,0x04040404,0x05050505};
This does declare an array, *not* a pointer. It's just that C implicitly adds a `&' when assigning an array value to a pointer variable or parameter.
Please try the following (not tested):
int carrayvalue[5] = {0x01010101,0x02020202,0x03030303,0x04040404,0x05050505}; int *carray = carrayvalue;
carray : __asmname__ 'carray' CCARRAY_PTR;
For this declaration the linker just passes a memory reference - to an array, not to a pointer. Pascal interprets the values found there as a pointer which is not what you want. Pascal does not know that this is in fact an array which must be `&'ed implicitly.
print_array(&carray); {this & seems wrong}
Indeed, and GPC should give you at least a warning.
On another matter, I downloaded the latest binary of GPC (gpc-19980830.i386-djgppv201.zip). Now, I keep getting a linker error about crt0.o. How do I overcome this?
Did you install gcc-2.8.1 for DJGPP in the first place? It's libraries are needed for GPC. Also, an old version of GPC or GCC can interfere with the new installation; better remove the old one.
Hope this helps,
Peter
On Mon, 7 Sep 1998, Peter Gerwinski wrote:
Thamm, Russell wrote:
Now, I keep getting a linker error about crt0.o. How do I overcome this?
Did you install gcc-2.8.1 for DJGPP in the first place? It's libraries are needed for GPC. Also, an old version of GPC or GCC can interfere with the new installation; better remove the old one.
I got the same error Thamm did :( I tried to correct it by copying crt0.o into the lib\gcc-lib\djgpp\2.81 directory, but then I get the following error:
D:\GCC\BIN/ld.exe: cannot open -lm: No such file or directory (ENOENT)
I even tried making sure that all the libraries in the directory are the same version, but still got the same error. Hopefully this gives you a clue to what it might be.
See ya! Orlando Llanes
"Meine Damen und Herren, Elvis hat soeben das Gebaeude verlassen!"
"Look out fo' flyeeng feet" O__/ a010111t@bc.seflin.org /|____. O <__. /> / \ ____________|_________ http://ourworld.compuserve.com/homepages/Monkey414
Orlando Llanes a écrit:
On Mon, 7 Sep 1998, Peter Gerwinski wrote:
Thamm, Russell wrote:
Now, I keep getting a linker error about crt0.o. How do I overcome this?
Did you install gcc-2.8.1 for DJGPP in the first place? It's libraries are needed for GPC. Also, an old version of GPC or GCC can interfere with the new installation; better remove the old one.
I got the same error Thamm did :
I have just dowloaded the same binaries and got the same error. The error comes from a wrong specs file coming with those binaries. All is correct with the original specs file coming from the DJGPP version of gcc 2.8.1 (which was correctly included in the previous binary djgpp distribution). I give it in attachment for convenience (it must be putted into the directory %DJGPP%\LIB\GCC-LIB\DJGPP\2.81).
Maurice Lombardi wrote:
I have just dowloaded the same binaries and got the same error. The error comes from a wrong specs file coming with those binaries.
Huppsa! :-(
All is correct with the original specs file coming from the DJGPP version of gcc 2.8.1 (which was correctly included in the previous binary djgpp distribution). I give it in attachment for convenience (it must be putted into the directory %DJGPP%\LIB\GCC-LIB\DJGPP\2.81).
I have included it into the binary distribution on Agnes.
Thanks,
Peter