Xref: utzoo comp.lang.c++:10928 comp.lang.c:34927 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!mit-eddie!bloom-beacon!eru!hagbard!sunic!news.funet.fi!hydra!kreeta!wirzeniu From: wirzeniu@cs.Helsinki.FI (Lars Wirzenius) Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: char* vs void* Message-ID: <10183@hydra.Helsinki.FI> Date: 28 Dec 90 18:19:41 GMT References: <11745@alice.att.com> <2778A795.6E71@tct.uucp> <17590@paperboy.OSF.ORG> Sender: news@cs.Helsinki.FI Organization: University of Helsinki, Department of Computer Science Lines: 35 In article <17590@paperboy.OSF.ORG> dbrooks@osf.org (David Brooks) writes: >In article <2778A795.6E71@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes: >> >>The ANSI C standard requires that |char *| and |void *| have identical >>representations. This requirement bows to existing practice. After >> [deleted] > >How's that again, again? > >I don't understand. In the case of void*, what is being represented? Pointers of type |char *| and |void *| are capable of pointing to *any* data object and that the way the compiler stores those types of pointers (their representation, that is) is the same. Given two pointer variables, void *void_ptr; char *char_ptr; and some data object, say data_object, and you assign the address of that object to both pointers, their bit patterns will be exactly the same: void_ptr = &data_object; char_ptr = (char *) &data_object; printf("%d", memcmp(&void_ptr, &char_ptr, sizeof(void *))); (the sizes of the two pointers are the same). The difference between |char *| and |void *| is that you can mix |void *| with pointers to other types without having to use casts. With |char *|, and any other pointer type except |void *|, you need the casts to make sure everything works on all machines. Lars Wirzenius wirzeniu@cs.helsinki.fi wirzenius@cc.helsinki.fi