Comments and explanations inline below. --- On Wed, 6/8/11, Julian Leviston <jul...@leviston.net> wrote:
From: Julian Leviston <jul...@leviston.net> Subject: [fonc] Issues with understanding obj.c To: "Fundamentals of New Computing" <fonc@vpri.org> Date: Wednesday, June 8, 2011, 11:00 AM Hi, I've been attempting to assimilate the corresponding code to Ian Piumerta's object model at http://piumarta.com/software/cola/objmodel2.pdf My C knowledge is lacking, because I don't understand some of the basics in it. I thought maybe some of you might be kind enough to elucidate. I really don't understand what this means: typedef struct object *(*method_t)(struct object *receiver, ...); method_t is a pointer to a function that returns an object pointer and takes receiver and additional argument typedef provides a new definition of a type based on an existing type, right? But what is the bit in brackets, and what is the ellipsis? Also, what is this? struct vtable *_vt[0]; Is that creating a pointer to a struct array which has zero elements in it? I don't follow what that's for? This is an idiom in C for variable-length arrays when at the end of a struct definition. The other thing I don't follow AT ALL is the negative 1 indexes. Code around line 128, point in case: struct object *vtable_allocate(struct vtable *self, int payloadSize) { struct object *object = (struct object *)alloc(payloadSize); object->_vt[-1] = self; return object; } what is object ->_vt[-1] = self; ? I mean, I "get" the object -> _vt bit, but the [-1] totally throws me. What's a negative 1 index on an array in C? I didn't even know you could do this. This is legal C and is equivalent to: *(vt-1) This is an idiom used in C for tagged objects and in the implementation of Object models (including C++) to store the vtable associated with an instance. Any help would totally be appreciated, or any referral to these "topics" on some educational resource somewhere. My old C books don't have these things in them at all. Julian. _______________________________________________ fonc mailing list fonc@vpri.org http://vpri.org/mailman/listinfo/fonc
_______________________________________________ fonc mailing list fonc@vpri.org http://vpri.org/mailman/listinfo/fonc