mercredi 22 mai 2019

warning: cast from 'char *' to 'float *' increases required alignment from 1 to 4 [-Wcast-align]

Is there a way for me to use the c++11 keyword alignas to decorate the function get(). Under certain condition I know that the buffer returned by get() will contain properly aligned floating point buffer.

Code:

$ cat c.cxx
extern char* get();

void foo()
{
  float *f = (float*)get();
}

leads to

$ clang++-8 -Wcast-align -c c.cxx
c.cxx:5:14: warning: cast from 'char *' to 'float *' increases required alignment from 1 to 4 [-Wcast-align]
  float *f = (float*)get();
             ^~~~~~~~~~~~~
1 warning generated.

Aucun commentaire:

Enregistrer un commentaire