I don't know if this is suitable to ask here, because this question is much more specific rather than general.
I've been reading this book: OOP in C - Axel Schreiner but find that it's hard to understand.
For example, in section 1.7: An Implementation — Set
If an object stores no information and if every object belongs to at most one set, we can represent each object and each set as small, unique, positive integer values used as indices into an array heap[]. If an object is a member of a set, its array element con- tains the integer value representing the set. Objects, therefore, point to the set containing them.
alongside with
#if ! defined MANY || MANY < 1
#define MANY 10
#endif
static int heap [MANY];
void * new (const void * type, ...)
{ int * p; /* & heap[1..] */
for (p = heap + 1; p < heap + MANY; ++ p)
if (! * p)
break;
assert(p < heap + MANY);
* p = MANY;
return p;
}
I cannot connect this two together.
What does "object stores no information" mean?
What does "every object belongs to at most one set" mean?
What does "If an object is a member of a set, its array element con- tains the integer value representing the set" mean?
I read it so hard but still cannot get it. Thanks.
Response to myself.
If an object stores no information and if every object belongs to at most one set, we can represent each object and each set as small, unique, positive integer values used as indices into an array heap[].
Let's say that a integer value can represent a set or an object. E.g:
0 represents an apple object
1 represents a banana object
2 represents an apple set
3 represents a banana set
In this case, object is merely an integer value, thus cannot store any information.
Also, integer values(0, 1, 2, 3) above can be used as indices of heap array.
If an object is a member of a set, its array element contains the integer value representing the set. Objects, therefore, point to the set containing them.
Following above example, 0(object apple) is a member of 2(set apple).
Therefore, heap[0] = 2.
Note: The conclusion heap[0] = 2 is only held under the condition that every object belongs to at most one set.