Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mimsy!oddjob!hao!noao!mcdsun!sunburn!gtx!edge!doug From: doug@edge.UUCP (Doug Pardee) Newsgroups: comp.lang.c Subject: How big is a (??? *) Message-ID: <737@edge.UUCP> Date: Mon, 11-May-87 17:15:46 EDT Article-I.D.: edge.737 Posted: Mon May 11 17:15:46 1987 Date-Received: Sat, 16-May-87 13:25:00 EDT Organization: Edge Computer Corporation, Scottsdale, AZ Lines: 47 Well, I would have thought that we'd have beaten this (char *)!=(int *) thing to death. But then I ran into a problem of my own... I want to do what is sometimes called "object-oriented" programming. Each source module consists of a bunch of routines which operate on a particular kind of object. Each instance of an object is described in detail by a struct which is malloc'ed by the object's "create" routine. Just that one source module knows the description of that struct. To the "outside world", each object is known only by a handle, which is typically (here it comes, folks) a pointer to that malloc'ed struct. Specifically, nobody will "#include foo.h" to get the struct definition. Unfortunately, as we've seen, that means that the outside world doesn't even know how big the pointer is. So, it seems that I can't use the straightforward approach of having the handle be the pointer to the structure. Possibility #1: We cavalierly declare that no pointers are longer than char pointers: sizeof (char *) >= sizeof (anything *) and create object handles by casting the pointers with (char *). Possibility #2: We cavalierly declare that all pointers to pointers are the same length: sizeof (char **) == sizeof (anything **) and the object's "create" routine should malloc(sizeof(struct foo *)) and return the pointer to the pointer as a (char **) handle. Possibility #3: We observe that malloc is declared as "char *", and so we assume that all pointers returned by malloc are truly (char *), even if we subsequently cast them to (struct foo *) and put a struct foo into that memory. #3a: we save the original (char *) pointer and return that as the handle. #3b: we cast the (struct foo *) pointer back into a (char *) pointer and return that as the handle [this is the same code as possibility #1, but with different reasoning]. I had considered a possibility #4, based on returning both the pointer and "sizeof pointer", but at best that seems to degenerate into a more complicated version of possibility #2. I'm leaning toward #3a. This would seem to be meaningful only when using malloc, which I am. -- Doug Pardee -- Edge Computer Corp., Scottsdale, AZ -- ...!ihnp4!mot!edge!doug