Hi,

I have some c code that I have put into my qt5 program but I get a lot of old-style-cast warnings which I would like to get rid of but don't quite know how to. I have tried reinterpret_cast but either I'm doing it incorrectly or it is not the right thing to do as it still results in the same error...

Thanks in advance!

Qt Code:
  1. warning: use of old-style cast [-Wold-style-cast]
  2. warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
To copy to clipboard, switch view to plain text mode 

Example code:
Qt Code:
  1. unsigned int j,k;
  2. unsigned int* jj;
  3. char* cptr;
  4. char buff[50];
  5.  
  6. jj = (unsigned int*)&tmpY; //recast as int as expected in htonl
  7. j = htonl(*jj); //convert to network format
  8. cptr = (char*)&j; //recast as a char * so can use indexing
  9. sprintf(buff,"Y=%7.2f ",tmpY);
  10. tmp=buff;
  11. s.append(buff);
  12. for(i=0;i<YLen;i++)
  13. {
  14. msg[YIndex+i] = cptr[i];
  15. }
To copy to clipboard, switch view to plain text mode