[Nickle] Struct/union subclassing syntax

Keith Packard keithp at keithp.com
Sat Jan 5 12:16:59 PST 2008


With fairly complete subtype/supertype support, nickle provides
limited-polymorphism for user types. However, it doesn't make
constructing subtypes easy. In fact, subtypes can only be constructed by
explicitly replicating the structure members from the supertype:

        typedef struct {
                int i;
        } super_t;
        
        typedef struct {
                int i;
                real f;
        } sub_t;

While this works just fine, it's rather clumsy, and is prone to errors
when the super type changes.

It seems like it would be nice to tie the two types together
syntactically, perhaps like:

        typedef struct super_t {
                real f;
        } sub_t;
        
or

        typedef struct extend super_t {
                real f;
        } sub_t;

the 'extend' keyword is already used for namespaces, with slightly
different semantics, there it adds names to an existing namespace, while
this time, it will inherit the members from the existing structure.

Of course, you could inherit from more than one struct quite easily:

        typedef struct extend super_t, another_super_t {
                real f;
        } sub_t;

Does this seem reasonable?

-- 
keith.packard at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : /pipermail/nickle/attachments/20080105/be4fda6e/attachment.pgp 


More information about the Nickle mailing list