Bug report (incompatible pointers)

Wed, 17 Sep 1997 19:03:54 +0100 (MET)


Dear GPC developers:

  This is my first mail to the list, so first of all: THANKS for a GREAT
pascal compiler!

However, the current version (970714; DJGPP version) cannot compile
(correctly) some programs with user-defined types.  The problem occurs in the
following situation:

  - Unit "u1" defined a type (say, myType)
  - Another unit, "u2", has a procedure with a parameter of type myType
  - The main program calls the procedure in "u2" (after having defined a
    variables of type myType).

I am sorry if this sounds cryptic (I tried to be precise), but there is an
example below.

Now, this example/setup works if myType is a pointer to a built-in type, or
an array of built-in types (ex: pointer to an array of doubles), but it does
NOT work if myType is more "complicated", e.g. a pointer to a record type [as
in the example below].  

There is a similar (related) problem with procedural parameters (and types).

I have included a simple example (below) which demonstrates the bug, and I
hope you are able to reproduce it.  Note that the program consists of two
units (u1, u2), as well as the main program.

Command line invoking GPC:

  gpc -o mainprg.exe mainprg.pas --automake

Compiler output:

  mainprg.pas: In function `program_Mainprg':
  mainprg.pas:14: warning: passing arg 1 of `Proc2' from incompatible pointer
  type

It is "only" a warning, and an .exe file is produces, but somestimes the
program crashes (not here, though).


Sincerely,

Jesper Lund
jel@hha.dk

P.S.  If you respond to the list, please include a CC to me (I may not have
been added the list yet). Thanks.


-------------------------------------------------------

program Mainprg;

uses
  u1, u2;

var
  y : RecPtr;

begin
  New (y);

  Proc2 (y);  { This call results in an incompatible pointer call }
end.          { Note that proc2 is in u2, where as recPtr is      }
              { defined in u1.                                    }

-----------------------------------------------------------------

unit u1;

interface

type
  rec = record
    a, b : Integer;
  end;

  recPtr = ^rec;

procedure Proc1 (x : recPtr);


implementation

procedure Proc1 (x : recPtr);
begin
  { Do nothing }
end;

begin

end. { u1 }


------------------------------------------------------------

unit u2;

interface

uses
  u1;

procedure Proc2 (x : recPtr);


implementation

procedure Proc2 (x : recPtr);
begin
  Proc1 (x);  { This call is OK -- no compiler errors! }
end;

begin

end. { u2 }

----------------------------------------------------------------



Jesper Lund (jel@hha.dk)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es