c++ difference between reinterpret cast and c style cast

后端 未结 4 672
南旧
南旧 2021-02-10 17:19

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:44

    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.

提交回复
热议问题