Article View: comp.std.c
Article #2375Re: Why no arithmetic on void *
From: Chip Salzenberg
Date: Wed, 23 Jan 1991 13:46
Date: Wed, 23 Jan 1991 13:46
37 lines
2011 bytes
2011 bytes
According to barmar@think.com (Barry Margolin):
>However, it would be nice if void* could also be used as a way to pass
>pointers to an array of arbitrary objects.
Of course it can.
Aside: In normal usage, what we call "pointer to an array" is usually
"pointer to the first element of the array." C _allows_ a declaration
of a genuine "pointer to an array," but such a pointer is typically no
more useful than a pointer to the first element.
In any case, a |void*| can represent all of the above pointer types.
>It seems to me that ANSI C only goes halfway in providing a generic
>pointer, because generic pointer arithmetic must be done by casting
>to a non-generic type, namely char*.
That's one interpretation. I see it as leveraging off existing
practice. Remember that |void*| and |char*| must have identical
representations and that sizeof(char) must always equal one. So
|char*| is just as generic a pointer as |void*|.
Given these facts, the utility of |void*| lay not in its similarities
to |char*|, but in its differences: conversions without casts and no
allowance for arithmetic.
>Future C standards might then be able to get rid of the notion that char
>is the fundamental unit ...
I see what you're driving at -- but such a language wouldn't be C any
more. Many existing programs would break. The assumption
"sizeof(char)==1" is hard-coded into innumerable calls to fread() and
other library functions.
--
Chip Salzenberg at Teltronics/TCT <chip@tct.uucp>, <uunet!pdn!tct!chip>
perl -e 'sub do { print "extinct!\n"; } do do()'
Technical Details
Message-ID:
<279D93D3.5EE7@tct.uucp>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!mips!daver!tscs!tct!chipReferences:
<1238@dkunix9.dk.oracle.com> <561@taumet.com> <1991Jan22.211212.14692@Think.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!mips!daver!tscs!tct!chip From: chip@tct.uucp (Chip Salzenberg) Newsgroups: comp.std.c Subject: Re: Why no arithmetic on void * Message-ID: <279D93D3.5EE7@tct.uucp> Date: 23 Jan 91 13:46:58 GMT References: <1238@dkunix9.dk.oracle.com> <561@taumet.com> <1991Jan22.211212.14692@Think.COM> Organization: Teltronics/TCT, Sarasota, FL Lines: 37