freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
Re: [freetds] pointer arithmetic on a pointer to void
- From: "James K. Lowden" <jklowden AT freetds.org>
- To: freetds AT lists.ibiblio.org
- Subject: Re: [freetds] pointer arithmetic on a pointer to void
- Date: Thu, 10 Oct 2013 20:57:03 -0400
On Thu, 10 Oct 2013 17:47:43 -0500
"Craig A. Berry" <craigberry AT mac.com> wrote:
> Since what we have now is dubious from a sC standards viewpoint,
> wouldn't it be better to just make it a pointer to char in the first
> place
Absolutely right on all counts. The only valid uses of void* are
1. compare with NULL
2. convert to char*
3. convert back to the type it points to
In olden times, as I'm sure you remember, the standard library declared
ordinary buffers to be char*, and the compiler never complained if you
happened to send int* (because, say, you're reading ints). With the
introduction of functional prototypes in C89, that was no longer
possible because the compiler would not "convert" int* to char* for
you. So ANSI invented void* to stand in for char*'s old role, albeit
in a more limited form. char* retained its elevated status: anything
could be cast to and from char* in order to gain byte-addressability.
Pointer arithmetic on void* is invalid for the perfectly good reason
that the void type has no size.
The choice between redefining the pointer to char* or casting void* to
char* is one of convenience. If your one-liner makes the compiler
happy, I'd say that's most convenient.
Thanks for pointing it out. I'm surprised it hasn't cropped up
before.
--jkl
-
[freetds] pointer arithmetic on a pointer to void,
Craig A. Berry, 10/10/2013
-
Re: [freetds] pointer arithmetic on a pointer to void,
James K. Lowden, 10/10/2013
-
Re: [freetds] pointer arithmetic on a pointer to void,
Craig A. Berry, 10/11/2013
- Re: [freetds] pointer arithmetic on a pointer to void, Frediano Ziglio, 10/12/2013
-
Re: [freetds] pointer arithmetic on a pointer to void,
Craig A. Berry, 10/11/2013
-
Re: [freetds] pointer arithmetic on a pointer to void,
James K. Lowden, 10/10/2013
Archive powered by MHonArc 2.6.24.