3

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.

Community
  • 1
  • 1
Niklas
  • 249
  • 3
  • 7

1 Answers1

6

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.

user657267
  • 20,568
  • 5
  • 58
  • 77