Mail Archives: djgpp/1998/12/25/22:15:29
On 25 Dec 98 at 21:23, Christian Hofrichter wrote:
> I have a void pointer and want to increase it by some bytes. Although I
> convert it into a char pointer I get a warning, everytime when compiling
> my code :
> "ANSI C++ forbids cast to non-reference type used as lvalue"
>
> That not so bad, but how can I deactivate or avoid this message ?
> What I did is:
> (unsigned char*)pointer+=4;
Try:
pointer = (char *)pointer + 4;
Casting in this way means the calculation is performed using
`char *'; the cast back to `void *' is implicit.
The warning generated by this:
pointer = pointer + 4;
is only enabled if you use `-pedantic' switch or explicitly
`-Wpointer-arith' in any case. So, to turn it off try using
the switch `-wpointer-arith' after your other options if
possible. I don't think this prevents the warning in
`-pedantic' mode, so maybe you need to turn that off too.
Note that there's a reason why ANSI forbids arithmetic on void
pointers -- I suggest you find a better way to do what you're
doing, if possible.
--
george DOT foot AT merton DOT oxford DOT ac DOT uk
- Raw text -