Article View: comp.lang.c.moderated
Article #2500Re: void* type
From: Konrad Schwarz
Date: Fri, 05 Apr 1996 00:28
Date: Fri, 05 Apr 1996 00:28
31 lines
1251 bytes
1251 bytes
In article <4jv7ge$d49@solutions.solon.com>, davis@space.mit.edu (John E. Davis) writes:
[on different pointer representations]
|> So, does this fail:
|>
|> double *d;
|> char *p;
|> unsigned int size;
|>
|> size = sizeof (double);
|> d = malloc (size);
|> p = malloc (size);
If you have correctly prototyped malloc, of course not. Malloc returns
a void * and the C compiler does a type conversion to the appropriate type.
Just like
# include <math.h>
{
int i = sin (0);
}
|> Is malloc smart enough to know
|> which representation to return?
No, but it is guaranteed to return a value that can be converted to a pointer
of any type.
Konrad Schwarz
Technical Details
Message-ID:
<4k1peh$4rj@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4ii34g$nlp@solutions.solon.com> <4jibl5$89u@solutions.solon.com> <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: schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz) Newsgroups: comp.lang.c.moderated Subject: Re: void* type Date: 4 Apr 1996 18:28:01 -0600 Organization: TU Wien Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4k1peh$4rj@solutions.solon.com> References: <4ii34g$nlp@solutions.solon.com> <4jibl5$89u@solutions.solon.com> <4jmcnh$lqk@solutions.solon.com> <4jq24r$aah@solutions.solon.com> <4jv7ge$d49@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com