Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-01

Got "Pointer", expected "Open Array Of Char"

10 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dave Coventry

Hi,

I have a procedure defined as follows:

procedure Copybytes(var dst: array of Char; src: array of Char; len: integer);

If I call it using the following:

Copybytes(@dst[dloc], at src[sloc],16);

I get an error:

dwg.pas(116,36) Error: Incompatible type for arg no. 2: Got "Pointer",
expected "Open Array Of Char"

Can anyone suggest a solution?

Kind Regards,

Dave Coventry

Reply by email

Dave Coventry
to leledumbo

Hi, thanks for the response.

leledumbo wrote
What's the type of dst and src that you pass to the function? Array is not pointer, and I have no idea about open array with var modifier. Open array is compatible with any array (and its subarrays through slicing).
dst and src are passed to the function that calls Copybytes();
function copy_compressed_bytes(var dst: array of Char; var dloc, sloc:
integer; src: array of Char;
  len: integer): integer;
begin
  Copybytes(@dst[dloc], at src[sloc],16);
  return 0;
end;

You may be onto something. dst is passed as a *var* because I'm interested in the destination array but can discard the src after it's been read.

I'll look into how the memory is allocated for src.

Many thanks.

Dave

Reply by email

Howard Page-Clark
to Dave Coventry
Dave Coventry wrote 9 lines
dst and src are passed to the function that calls Copybytes(); function copy_compressed_bytes(var dst: array of Char; var dloc, sloc: integer; src: array of Char; len: integer): integer; begin Copybytes(@dst[dloc], at src[sloc],16); return 0; end;

I think making src also a var parameter and structuring the signatures for the routines without @ as follows will work:

procedure Copybytes(var dst, src: array of Char; len: integer);
...
function copy_compressed_bytes(var dst: array of Char;
                                var dloc, sloc:integer;
                                src: array of Char;
                                len: integer): integer;
begin
   Copybytes(dst[dloc],src[sloc],16);
   Exit(0);
end;

Reply by email

Dave Coventry
to leledumbo
leledumbo wrote
Or const since it's meant to be read only

Hmmm.

Doesn't help. Still getting the same error.

I've tried passing the src parameter as a Pointer and then casting it as an array of Char.

procedure Copybytes(var dst: Pointer; src: Pointer; len: integer);
var
  i: integer;
  data_in,data_out: Array of Char;
begin
  ;
  ;
  for i:=0 to len-1 do
  begin
    data_out[i]:=data_in[i];
  end;
end;
Calling the procedure:     Copybytes(@dst[dloc], at src[sloc],16);

I get the error

Error: Can't assign values to an address

Reply by email

Howard Page-Clark
to Dave Coventry
Dave Coventry wrote 28 lines
On 13 January 2013 14:56, leledumbo wrote: > Or const since it's meant to be read only Hmmm. Doesn't help. Still getting the same error. I've tried passing the src parameter as a Pointer and then casting it as an array of Char. procedure Copybytes(var dst: Pointer; src: Pointer; len: integer); var i: integer; data_in,data_out: Array of Char; begin ; ; for i:=0 to len-1 do begin data_out[i]:=data_in[i]; end; end; Calling the procedure: Copybytes(@dst[dloc], at src[sloc],16); I get the error Error: Can't assign values to an address

One source of confusion arises because your parameter declaration "array of char" in procedure Copybytes(var dst: array of Char ... means something different from your variable declaration

var
  data_in, data_out: Array of Char;

where "Array of Char" denotes a dynamic array - rather different from the parameter-passing declaration.

Reply by email