Re: Is strongly-typed programming conceivable for C code using gcc ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Alexandre,

Taking Dima's solution in conjunction with the way Apple solved their
similar problem by using opaque types in Cocoa and Carbon:

struct CW_C_MsgUp_s;
typedef struct CW_C_MsgUp_t* CW_C_MsgUp_t;

struct CW_C_MsgDown_s;
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
CW_C_MsgDown_new() provides.

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...

CW_C_MsgUp_t *my_up_msg;
CW_C_MsgDown_t *my_down_msg;

...to this...

CW_C_MsgUp_t my_up_msg;
CW_C_MsgDown_t my_down_msg;

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux