This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Hi, Alexandre.
 It seems that you are starting to write some project using the ADT technique,
on C. Here some link to a book I didn't read. (I never programmed on C).
Our lecturers say that this book is not _so_ good, but it is what
de facto they want to teach on courses on C, so it is recommended.
http://www.cs.technion.ac.il/users/yechiel/CS/Interesting/BugFreeC.html

Regards,
 Dima.

On 9/19/07, John Love-Jensen <eljay@adobe.com> wrote:
> 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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]