[Zlib-devel] zlib 1.2.3.5 available for testing

Török Edwin edwintorok at gmail.com
Sat Jan 9 04:22:16 EST 2010


On 2010-01-09 05:13, Mark Adler wrote:
> On Jan 8, 2010, at 2:11 AM, Török Edwin wrote:
>   
>> 1. Portability
>> gzread.c:425:13: warning: use of GNU void* extension [-Wpointer-arith]
>>        buf += n;
>>        ~~~ ^  ~
>>
>> gzwrite.c:195:17: warning: use of GNU void* extension [-Wpointer-arith]
>>            buf += n;
>>            ~~~ ^  ~
>>     
>
> What I had there before which worked fine a few years ago was:
>
>     (char *)buf += n;
>
> Makes sense, right?  Well now I get a nastygram from the compiler for that: "warning: target of assignment not really an lvalue; this will be a hard error in the future."  So I changed it to:
>   

Yes it would make sense, but gcc 4.1 and 4.4 already reject that :(
gzread.c:425: error: lvalue required as left operand of assignment

clang gives a slightly better error message here:

gzread.c:425:10: error: assignment to cast is illegal, lvalue casts are
not supported


>     buf += n;
>
> but apparently some compilers hate that as well.  It used to be that any self-respecting compiler knew what you meant when you did arithmetic on a void * pointer, i.e. that you meant for the units to be bytes.

gcc (and clang) know how to do void* arithmetic, but with -pedantic they
warn that some other compilers may not know.

>   And I have no idea why (char *)buf, a cast of a pointer to another pointer type, is no longer a pointer.

It is a pointer, but gcc refuses to assign something to a cast. There is
probably an explanation in the C standard, but this is certainly
counter-intuitive.
Also some older versions of gcc even documented this as a C extension
supported by gcc (see Generalized LValues in gcc 3.3), but that
documentation (and support) seems to be gone from newer gcc versions.

>   Why there has been such a vicious attack on the expressiveness of C, I have no idea.  I blame it all on religious extremists.  Anyway, I digress.  Please try this in those two places:
>
>     buf = (char *)buf + n;
>
> and let me know what complaint you get then.  Thanks.
>   

Making this change makes those pedantic warnings go away, thanks.

Best regards,
--Edwin





More information about the Zlib-devel mailing list