[Zlib-devel] Allow read-only data as input
Sebastian Huber
sebastian.huber at embedded-brains.de
Tue Mar 29 10:32:06 EDT 2011
On 29/03/11 14:49, Cosmin Truta wrote:
> Lasse Collin wrote:
>
>> I agree that it could have been nice to have the const there, but I
>> think it is too late to change it. Existing applications already have
>> the required casts. Adding the const now would require fixing
>> applications that assume that next_in isn't const.
>>
> Generally, there should be no need to change any surrounding code if
> the lvalue changes from a non-const pointer to a const pointer.
>
> int *p;
> int *q;
> p = q;
>
> can be changed to
>
> const int *p;
> int *q;
> p = q;
>
Yes, but not q = p, or parameter_is_non_const(p) (like free()). I don't
think that
free(z_steam.next_in)
is a big deal since z_stream.next_in changes after processing and thus
is in most cases not suitable to free something. I don't know if it is
acceptable to break existing zlib user code, but the option to allow
read-only input data without a cast would be nice. The
#define I_WANT_CONST
#include <zlib.h>
approach seems to be a good solution.
More information about the Zlib-devel
mailing list