gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Opaque type history


From: Gaius Mulley
Subject: Re: Opaque type history
Date: Mon, 03 Jun 2024 16:09:26 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

john o goyo <jog37@riddermarkfarm.ca> writes:

> Greetings, Gaius.
>
> ISO/IEC 10514 states (Sect. 6.1.5.1 p. 34) that "Opaque types cannot
> be declared as a scalar type."  It also notes that PIM3 mandated that
> an opaque type must be declared as a pointer type.  However, the 1980
> Modula-2 report (Sect. 16 p. 30) also allowed subranges of standard
> types.  This explains some issues found in legacy PIM2 code.
>
> Of course, gm2 allows this via -fextended-opaque.
>
> Sincerely,
> john

Hi John,

yes indeed - I've just checked the error message from gm2 and uncovered
a bug in the error message:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115330

$ cat Num.def 
DEFINITION MODULE Num ;

TYPE
   NumType ;

PROCEDURE add (left, right: NumType) : NumType ;

END Num.

$ cat Num.mod 
IMPLEMENTATION MODULE Num ;

TYPE
   NumType = CARDINAL ;

PROCEDURE add (left, right: NumType) : NumType ;
BEGIN
   RETURN left+right
END add ;

END Num.

$ gm2 Num.mod 
Num.mod:4:14: error: In definition module ‘wrapc’: opaque type (NumType) should 
be equivalent to a POINTER or an ADDRESS
    4 |    NumType = CARDINAL ;
      |              ^~~~~~~~
Num.mod:4:14: error: if you really need a non POINTER type use the 
-fextended-opaque switch



wrapc is incorrect - it should be Num (I will fix this).  By default gm2
expects a pointer type for opaque - but as you mention - the limitation
can be overridden by -fextended-opaque.

Interestingly it also catches this when compiling the test module:


$ cat test.mod 
MODULE test ;

FROM Num IMPORT NumType, add ;

VAR
   l, r,
   res : NumType ;
BEGIN
   res := add (l, r)
END test.

$ gm2 test.mod 
./Num.mod:4:14: error: In definition module ‘wrapc’: opaque type (NumType) 
should be equivalent to a POINTER or an ADDRESS
    4 |    NumType = CARDINAL ;
      |              ^~~~~~~~
./Num.mod:4:14: error: if you really need a non POINTER type use the
-fextended-opaque switch


regards,
Gaius



reply via email to

[Prev in Thread] Current Thread [Next in Thread]