Trying to use a uint*& as a const unit*& fails: invalid initialization of reference of type ‘const uint8_t*&’ from expression of type ‘uint8_t*

后端 未结 1 497
小鲜肉
小鲜肉 2021-01-26 06:12

The following code fails to compile for me (gcc 4.6.3, Ubuntu 12.04):

#include 
#include 

static inline void adjustBuffer(cons         


        
相关标签:
1条回答
  • 2021-01-26 06:41

    Passing an uint8_t * as a const uint8_t *& parameter would allow the function to replace the unint8_t * with a const uint8_t *. Now there is a const uint8_t *in the place where the caller expects a modifiable uint8_t *. This is not save, since the caller might modify the pointed-to data after the function returned.

    The problem is the same as in this C++ FAQ lite section.

    0 讨论(0)
提交回复
热议问题