Is strongly-typed programming conceivable for C code using gcc ?
Wed Sep 19 15:53:00 GMT 2007
Taking Dima's solution in conjunction with the way Apple solved their
similar problem by using opaque types in Cocoa and Carbon:
typedef struct CW_C_MsgUp_t* CW_C_MsgUp_t;
typedef struct CW_C_MsgDown_t* CW_C_MsgDown_t;
This will insulate your implementation of those opaque types from the public
header files (note that the structs are forward references, and not declared
publically), and allow you some measure of type safety in C.
Apple uses a factory function to create their opaque types, and for most
opaque types the CFRelease function to destruct them (using a reference
counting mechanism). That's the role that CW_C_MsgUp_new() and
As far as them being pointers... I believe that you will want them to be
pointers baked into the typedef.
The one change to your code would be to change from this...
More information about the Gcc-help