On Wed, Sep 25, 2002 at 02:21:13AM +0900, William Djaja Tjokroaminata wrote:
> Thanks for the explicit example.  I see, so we use some naming convention
> and take advantage of the C pre-processor to determine the function at
> compile time.  It seems that this approach is very maintainable and much
> better than keeping the function pointers.  (Hey, can I then actually
> write object-oriented model using only C from scratch easily? :) I don't
> know about objective-C.)

I wouldn't exactly call this easy; with the code I've written, you still
don't have type checking or virtual functions or a whole lot of features
you need to write object-oriented code.  Take a look at GTK+; they've
already done a lot of this work for you.

> On another slightly different subject, I think last time it was suggested
> in C object creation, one approach is to create the inner objects before
> the outer objects.  However, assuming arbitrarily complex and nested mix
> of VALUE's and C data in the struct's, I don't think this approach is
> foolproof.  The problem is if when creating the inner objects the gc 
> actually gets invoked, these inner objects are swept away.  I don't know
> whether the double initialization technique is really foolproof.

Put a reference to the inner object on the stack immediately after
calling Data_Wrap_Struct, and the object won't get collected until the
some time after the stack is unwound.

Paul