mercredi 29 janvier 2020

How to cast int pointer to float pointer

I am running cppcheck (c++11) against a library that contains many casts similar to the below:

// Allocates various buffers
int*   i_buffer = (int*)   calloc (500, sizeof (int));
float* f_buffer = (float*) i_buffer;

For these casts, I see the following message:

"portability","invalidPointerCast","Casting between integer* and float* which have an incompatible binary data representation."

What is the correct way to perform the type of cast shown above ? What is the potential consequence of casting the pointer the way it is shown above ?

Aucun commentaire:

Enregistrer un commentaire