Non null-terminated string compiler option for gcc

前端 未结 5 1836
慢半拍i
慢半拍i 2020-12-11 04:01

Update

turns out this is just another case of \"c++ is not c blues\"


What I want

const char hex[16] = \"0123456789ABCDEF\";
         


        
5条回答
  •  半阙折子戏
    2020-12-11 04:56

    I believe the question is a bit unclear: In C, the qoted initialization:

    static const char hex[16] = "0123456789ABCDEF";
    

    is legal. In C++, it is not. So it is one of the pieces of code, that fail (fortunately at compile time), when you move from C to C++.

    It would be nice to have a way to force string literals without termination \0 byte. Something like:

    static const char hex[16] = "0123456789ABCDEF\!0";
    

    where the \!0 at the end tells the compiler to not zero-terminate the string! \! or even \!0 anywhere else in the string would behave unmodified, so just put out a literal ! or !0 .

提交回复
热议问题