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