Replies: 1 comment 2 replies
-
It's not exactly equivalent to what you can do in C. In particular, you can only have opaque reference types in M3. (I seem to remember there is a way to do opaque structs in C, but I haven't actually seen it done much.) What you do is declare a type to exist such as... TYPE T <: REFANY; This tells any importer of the declaration (since it would normally be in an interface file) that type T exists and is a reference type. The importer can do whatever it can do with REFANY to objects of type T, plus it can NEW a T. More usefully, TYPE T <: OBJECT METHODS init() : T END; means to an importer that it can for example do VAR t : T := NEW(T).init(); and not much else (well, whatever it can do with REFANY : store it, check it for equality, etc.) The conventional way to use this (but obviously not the only way!) is as follows: in your interface: Declare T as an object with whatever methods you want to be public: INTERFACE MyType; TYPE T <: OBJECT METHODS init() : T; publicOp(); END; Then in the implementation: MODULE MyType; REVEAL T = (OBJECT METHODS init() : T; publicOp(); END) BRANDED OBJECT privateField : PfType; OVERRIDES init := Init END; The re-typing of "OBJECT METHODS init() : T; publicOp(); END" is painful so even more conventionally: INTERFACE MyType; TYPE T <: Public; Public = OBJECT METHODS init() : T; publicOp(); END; (giving a name to "OBJECT METHODS init() : T; publicOp(); END") and then MODULE MyType; REVEAL T = Public BRANDED OBJECT privateField : PfType; OVERRIDES init := Init END; BRANDED is required here so that a client of the interface can't construct its own matching type and sneak a peek at privateField. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Reading through the language manual, it's still unclear to me. C's declaration is like this, what is the equivalent in M3?
typedef struct _TREEITEM *HTREEITEM;
@mikanystrom @mikanystrom-intel
Beta Was this translation helpful? Give feedback.
All reactions