Skip to content

Passing two dimensional array as an argument results in incompatible pointer type error. #105

Open
@tkurtbond

Description

@tkurtbond

Given the following program, BrokenArray.Mod:

MODULE BrokenArray;
  IMPORT Out;

  VAR
    i, j: INTEGER;
    a1: ARRAY 2, 3 OF LONGINT;

  PROCEDURE p (a: ARRAY OF ARRAY OF LONGINT);
  BEGIN
    Out.String ('LEN (a,0): '); Out.Int (LEN(a,0), 0); Out.Ln;
    Out.String ('LEN (a,1): '); Out.Int (LEN(a,1), 0); Out.Ln;
  END p;

BEGIN
  FOR i := 0 TO LEN (a1, 0) DO
    FOR j := i TO LEN (a1, 1) DO
      a1[i,j] := i * j;
    END;
  END;

  p (a1);
END BrokenArray.

I get the following results:

$ voc -f -m BrokenArray.Mod BrokenArray.Mod  Compiling BrokenArray.  Main program.  1050 chars.
BrokenArray.c: In function ‘main’:
BrokenArray.c:47:23: error: passing argument 1 of ‘BrokenArray_p’ from incompatible pointer type [-Wincompatible-pointer-types]
   47 |         BrokenArray_p(BrokenArray_a1, 2, 3);
      |                       ^~~~~~~~~~~~~~
      |                       |
      |                       INT32 (*)[3] {aka int (*)[3]}
BrokenArray.c:19:35: note: expected ‘INT32 *’ {aka ‘int *’} but argument is of type ‘INT32 (*)[3]’ {aka ‘int (*)[3]’}
   19 | static void BrokenArray_p (INT32 *a, ADDRESS a__len, ADDRESS a__len1)
      |                            ~~~~~~~^
C compile and link: gcc -fPIC -g -I "/usr/local/sw/versions/voc/git/2/include"   BrokenArray.c  -o BrokenArray -L"/usr/local/sw/versions/voc/git/lib" -lvoc-O2
-- failed: status 0, exitcode 1.
Terminated by Halt(1). 

This is on Fedora 40 with gcc (GCC) 14.2.1 20240801 (Red Hat 14.2.1-1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions