Article View: comp.lang.c.moderated
Article #2508Re: void* type
From: news
Date: Fri, 05 Apr 1996 00:39
Date: Fri, 05 Apr 1996 00:39
29 lines
1646 bytes
1646 bytes
davis@space.mit.edu writes: [on a DPS-6000] >So, does this fail: > > double *d; > char *p; > unsigned int size; > > size = sizeof (double); > d = malloc (size); > p = malloc (size); > >What is the difference between d and p? Is malloc smart enough to know >which representation to return? malloc returns a void *. The assignments to d and p convert the void * to double * and char *, respectively. No change is needed for the char *, but the return value from malloc is reduced from 32 bits to 16 bits to convert to a double *. Since malloc guarantees alignment (actually, only *after* casting, but only a very malicious malloc would do that to you), this can safely be done. The DPS-6000 has 16-bit words. A word address fits into one 16-bit word. An extra bit is needed, in another word, to distinguish the two bytes in a word. I think this "byte" pointer is a an artefact of the C implementation, to save space: the hardware itself thinks bytes are words are 16 bits. -- David Tanguay dat@Thinkage.on.ca http://www.thinkage.on.ca/~dat/ Thinkage, Ltd. Kitchener, Ontario, Canada [43.24N 80.29W]
Technical Details
Message-ID:
<4k1q3p$5bj@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4jmcnh$lqk@solutions.solon.com> <4jq24r$aah@solutions.solon.com> <4jv7ge$d49@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: news@Thinkage.On.CA Newsgroups: comp.lang.c.moderated Subject: Re: void* type Date: 4 Apr 1996 18:39:21 -0600 Organization: Thinkage Ltd., Kitchener, Ontario Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4k1q3p$5bj@solutions.solon.com> References: <4jmcnh$lqk@solutions.solon.com> <4jq24r$aah@solutions.solon.com> <4jv7ge$d49@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com