Search code examples
c++avravr-studio6

reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away qualifiers


I want to use Adafruit_CC3000 arduino library in AVR Studio. I have followed this Instruction to use Adafruit arduino lib with AVR studio so i can use other AVR function too. But I am getting the same error 50 times while i compile the code.

Error 5 reinterpret_cast from type 'const char*' to type '__FlashStringHelper*' casts away qualifiers E:\arduino-1.0.1\libraries\Adafruit_CC3000\Adafruit_CC3000.cpp 183 3 ATmega32_WSClient_CC3K

I have searched on web for such kind of errors. but i failed to understand the issue. I am requesting to make me understand which thing in this code is generatig this error?


Solution

  • reinterpret_cast can convert between unrelated pointer types, but can't remove const or volatile qualifiers. You need const_cast for that.

    Options are (roughly in order of increasing nastiness):

    • don't use the wrong pointer type in the first place;
    • cast to const __FlashStringHelper*, if you don't need to modify the object;
    • cast from char* if you do need to modify it;
    • use reinterpret_cast<__FlashStringHelper*>(const_cast<char*>(whatever)) or the brute-force (__FlashStringHelper*)whatever if you insist on abandoning the type system entirely.