🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2515

Re: void* type

#2515
From: news
Date: Fri, 05 Apr 1996 00:38
32 lines
1657 bytes
In article <4jv7ge$d49@solutions.solon.com> davis@space.mit.edu writes:
>
>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?

Assuming that you also have
    #include <stdlib.h>
Then this does not fail.  (If you don't the sequence could fail on any
number of systems).

No "malloc" is not "smart enough" to return different representations.
It ALWAYS returns a void*.  The compiler however, know that d and p
have different representations and compiles different code to handle
the assignment.  The code to handle a conversion from void* to double*,
is different than that for void* to char*.

To answer the specific question about the DPS/6.  A char * or void*
consists of two parts, a word pointer (32 bits) and character index
from that (16 bit).  The reflects the way the hardware works.  Pointer
registers only point at word boundaries.  Since a double can only
start at a word boundary, a pounter to double does not not have
the 16 bit character offset part.
Technical Details
Message-ID: <4k1q2q$5ae@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <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:38:50 -0600
Organization: Thinkage Ltd.
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4k1q2q$5ae@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