delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/25/22:15:29

Message-Id: <199812260315.WAA30107@delorie.com>
Comments: Authenticated sender is <mert0407 AT sable DOT ox DOT ac DOT uk>
From: "George Foot" <george DOT foot AT merton DOT ox DOT ac DOT uk>
To: Christian Hofrichter <ChristianHofrichter AT gmx DOT de>
Date: Sat, 26 Dec 1998 03:14:46 +0000
MIME-Version: 1.0
Subject: Re: void pointer arithmetic causes warning message
CC: djgpp AT delorie DOT com
X-mailer: Pegasus Mail for Win32 (v2.42a)
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019