c++ difference between reinterpret cast and c style cast

后端 未结 4 1343
栀梦
栀梦 2021-02-10 17:38

Code:

char keyStr[50]={ 0x5F, 0x80 /* bla bla */ };
uint32_t* reCast  = reinterpret_cast< uint32_t* >( &keyStr[29] );
uint32_t* reCast2 = ( uint32_t* )         


        
4条回答
  •  半阙折子戏
    2021-02-10 17:53

    The difference is that with C-style cast in C++ file in some cases you will get error and cannot compile. reinterpret_cast solves such cases. Something like - you tell to compiler: "I know it is incompatible casting, but let assume it is ok". C++ is far more restricted than C for such things like casting.

提交回复
热议问题