Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!husc6!cmcl2!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.lang.c Subject: Re: How big is a (??? *) Message-ID: <790@mcgill-vision.UUCP> Date: Tue, 2-Jun-87 21:46:42 EDT Article-I.D.: mcgill-v.790 Posted: Tue Jun 2 21:46:42 1987 Date-Received: Thu, 11-Jun-87 03:00:54 EDT References: <737@edge.UUCP> Organization: McGill University, Montreal Lines: 31 In article <737@edge.UUCP>, doug@edge.UUCP (Doug Pardee) writes: > Well, I would have thought that we'd have beaten this > (char *)!=(int *) thing to death. I rather think we have.... > I want to do what is sometimes called "object-oriented" programming. > [wants to return "handles" to internal structures] > 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 *). This should work, but not because of the reason you quoted. K&R says, and presumably ANSI follows them in saying, that a pointer to any object can be cast to a pointer to any smaller object and back without change. Since a char is the smallest object available, any pointer can be cast to (char *) and back without change. Therefore, this scheme is safe, regardless of the sizes of the pointers. (Since more of a smaller object can fit into memory, this would tend to imply the inequality you quoted, but it does not require it.) If ANSI does not support this argument, I would certainly hope they have some analogous pointer type, which can be substituted for (char *) to repair the above exposition. der Mouse (mouse@mcgill-vision.uucp)