
pointer arithmetic with a pointer to void
Quote:
> Hi all,
> I pretty much get how pointer arithmetics works with pointer to
> 'real' types (that is not to void). Now I am wondering though : what is
> allowed/defined/advised when handling pointers to void. Tests on some
> compilers have shown that they handle it as I expected (i.e. exactly as
> a char *) as far as arithmetics. I am wondering though if this is mere
> luck, or if this is defined is standard C (actually, my doubts arise
> because of a recent post of Tobias in one of my threads "two-dimensional
> arrays").
> So, thanks in advance for your feedback. Please, emlighten me : )
I would figure this is pure luck, and pointer arithmetic with void
pointers is not defined by the C standard.
Here is some results from a simple test I did. Proof by example is not
valid proof, but you can get the general idea.
int main(void) {
char a;
void *p=&a;
p+1;
return 0;
Quote:
}
hoo.c: In function `main':
hoo.c:4: warning: pointer of type `void *' used in arithmetic
hoo.c:4: warning: statement with no effect
--
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"I will never display my bum in public again."
- Homer Simpson