[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Error with Opaque types in GNU Modula-2?
From: |
T . Kurt Bond |
Subject: |
Error with Opaque types in GNU Modula-2? |
Date: |
Wed, 15 Jan 2025 10:40:38 -0500 |
User-agent: |
Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (Gojō) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (x86_64-redhat-linux-gnu) MULE/6.0 (HANACHIRUSATO) |
I've got the following program consisting of three files. First,
MinOpaque.def:
DEFINITION MODULE MinOpaque;
TYPE Opaque;
PROCEDURE Make (VAR o: Opaque; i: INTEGER);
END MinOpaque.
Next, MinOpaque.mod:
IMPLEMENTATION MODULE MinOpaque;
FROM Storage IMPORT ALLOCATE, DEALLOCATE;
FROM SYSTEM IMPORT TSIZE;
TYPE Opaque = POINTER TO INTEGER;
PROCEDURE Make (VAR o: Opaque; i: INTEGER);
BEGIN
ALLOCATE (o, TSIZE (Opaque));
o^ := i;
END Make;
END MinOpaque.
Finally, TryMinOpaque.mod:
MODULE TryMinOpaque;
FROM InOut IMPORT WriteString, WriteLn, WriteInt;
FROM MinOpaque IMPORT Opaque, Make;
VAR o: Opaque;
BEGIN
Make (o, 10);
o^ := 20; (* I thought this was illegal. *)
WriteString ("o^: "); WriteInt (o^, 0); WriteLn;
END TryMinOpaque.
I thought you didn't have access to the internals of type Opaque in
Modula-2. Is this a bug in gm2, or am I misunderstanding?
$ gm2 --version
gm2 (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This is on Fedora 41 with
$ uname -a
Linux atla 6.12.8-200.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jan 2 19:26:03
UTC 2025 x86_64 GNU/Linux
--
T. Kurt Bond, tkurtbond@gmail.com, tkurtbond.github.io, consp.org, & tkb.tx0.org
- Error with Opaque types in GNU Modula-2?,
T . Kurt Bond <=