arithmetic on void pointers
Stephen J. Friedl
friedl at vsi.COM
Tue Mar 7 13:45:32 AEST 1989
In article <1527 at ncar.ucar.edu>, russ at groucho.ucar.edu (Russ Rew) writes:
> What does the latest dpANS document say? Is it legal
> to increment a variable of type void* ?
No.
When incrementing a pointer, one multiplies the increment by the
size of the pointed-to object. Since a `void' has no size, you
can't get to the next one.
The dpANS does not directly say "You can't ++ a void*", so to prove
it you need to string a couple of parts together.
>From the May88 dpANS: (renditions: ITALICS, /Courier/)
3.1.2.5 - Types
"The /void/ type comprises an empty set of values; it
is an incomplete type that cannot be completed"
### /void/ is an incomplete type
3.3.3.4 - The /sizeof/ operator
"The /sizeof/ operator shall not be applied to an
expression that has function type or an incomplete
type [...]"
### you can't take the size of /void/
3.3.2.4 - Postfix increment and decrement operators
and 3.3.3.1 - Prefix increment and decrement operators
"The operand of the prefix increment or decrement
operator shall have qualified or unqualified scalar
type and shall be a modifiable lvalue."
### you can't ++ or -- a /void/
I would guess that those implementations that permit ++ on
void pointers do so by treating them as char pointers instead.
Steve, the staggering dpANS (with apologies to Karl)
--
Stephen J. Friedl / V-Systems, Inc. / Santa Ana, CA / +1 714 545 6442
3B2-kind-of-guy / friedl at vsi.com / {attmail, uunet, etc}!vsi!friedl
"Cold beer, hot women, and fast compilers" - me
More information about the Comp.lang.c
mailing list