🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9747

Re: sizeof(char)

#9747
From: Doug Gwyn
Date: Fri, 07 Nov 1986 02:37
27 lines
2382 bytes
In article <1294@ttrdc.UUCP> levy@ttrdc.UUCP (Daniel R. Levy) writes:
>A question:  what about the jillions of C programs out there which
>declare "char *malloc()"?  Will they all need to be changed?  Common
>sense says no, since malloc() is supposed to return a "maximally aligned"
>address anyhow, so as far as anyone cares it could be declared float * or
>double * or short int * or (anything else)*  if malloc() in the malloc() code
>itself were declared the same way.  So if "char" happened to be a two byte
>quantity, no sweat, right?  Or was there any particular reason for declaring
>malloc() to be a "char *"?   And thus, might something break in malloc() or
>the usage thereof if char might no longer be the smallest addressable quantity?

X3J11 malloc() returns type (void *) anyway, so this is already an issue
independently of the multi-byte (char) issue.  The answer is, on most
machines the old (char *) declaration of malloc() will not result in
broken code under X3J11, but it is POSSIBLE that it would break under
some X3J11 implementations (one assumes that the implementer will take
pains to keep this from happening if at all possible).

Under the multi-byte (char) proposal, malloc() still returns (void *)
and is not affected at all by the proposal.  sizeof() still returns
the number of primitive storage cells occupied by a data object, which
is still the right information to feed malloc() as a parameter.

The X3J11 draft proposed standard as it now stands has actually managed
to enforce a rather clean distinction between (char) data and arbitrary
data.  The additional changes to the draft to introduce a separate data
type for the smallest addressable storage unit are really very minor.
Technical Details
Message-ID: <5253@brl-smoke.ARPA>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!brl-adm!brl-smoke!gwyn
References: <4617@brl-smoke.ARPA> <657@dg_rtp.UUCP> <55@cartan.Berkeley.EDU> <663@dg_rtp.UUCP> <5141@brl-smoke.ARPA> <1294@ttrdc.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!brl-adm!brl-smoke!gwyn
From: gwyn@brl-smoke.ARPA (Doug Gwyn )
Newsgroups: net.lang.c
Subject: Re: sizeof(char)
Message-ID: <5253@brl-smoke.ARPA>
Date: Thu, 6-Nov-86 21:37:23 EST
Article-I.D.: brl-smok.5253
Posted: Thu Nov  6 21:37:23 1986
Date-Received: Fri, 7-Nov-86 22:55:57 EST
References: <4617@brl-smoke.ARPA> <657@dg_rtp.UUCP> <55@cartan.Berkeley.EDU> <663@dg_rtp.UUCP> <5141@brl-smoke.ARPA> <1294@ttrdc.UUCP>
Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>)
Organization: Ballistic Research Lab (BRL), APG, MD.
Lines: 27