Home Ask Login Register

Developers Planet

Your answer is one click away!

Niklas February 2016

Why isn't zlibs z_stream::next_in const?

I am currently integrating code from another stack-overflow question, that uncompresses data from a QByteArray into an application.

Since we enabled all the compiler errors, we have to reinterpret_cast and const_cast the QByteArray::data():

z_stream strm;
strm.next_in = reinterpret_cast<Bytef *>(const_cast<char *>(data.data()));

Why would this input parameter be non-const? In my opinion, this suggests, that the data is somehow modified, which is definitely not what I want and also not what I believe is actually happening.


user657267 February 2016

By default the z_stream interface functions aren't const, presumably for legacy reasons.

You can build zlib with const support however by running configure with --const.

Post Status

Asked in February 2016
Viewed 2,893 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life