Opaque Types in Modula-2

My knowledge of Modula-2 is limited to having read Programming in Modula-2 and having written a few toy programs.

I'm a little confused about opaque types in Modula-2. They are mentioned in passing in Programming in Modula-2, 4E, Chapter 24, "Definition and Implementation Parts", on page 83. I thought that to make an opaque type, you declared a type in the definition module as

and then in the implementation module you finish that declaration as

with a pointer to an internal type that is not mentioned in the definition module, and which is thus not visible to clients of the module.

However, that doesn't seem to work, in the example I wrote and compiled. I'm using GNU Modula-2 with the PIM4 libraries (it's nice that GM2 is in the standard Fedora repository now, no doubt helped by GM2 being officially accepted into gcc).

Here's Opaque.def:

And here's Opaque.mod:

And here is the test program:

I had expected that the compiler would refuse to compile the references to "o^.i".

Could anyone clear up my confusion?

Posted in: s/pascal

👽 TKurtBond

2024-12-24 · 1 year ago · 👍 norayr

4 Comments ↓

🐙 norayr [mod] · 2024-12-30 at 00:17:

dsar, who is an expert in m2 said about your post:

By the way, that code shouldn't compile, you can't access members of an opaque type

👽 TKurtBond [OP] · 2024-12-31 at 22:46:

And that’s what I thought, too. Maybe a bug in GNU Modula-2?

🐙 norayr [mod] · 2025-01-06 at 01:14:

it's possible. if you write in gm2 mailing list, gaius will respond.

👽 TKurtBond [OP] · 2025-01-15 at 20:32:

Emailed gm2 mailing list.

— Error with Opaque types in GNU Modula-2?