更新
事实证明这只是“c++ 不是 c 蓝调”的另一种情况
我想要什么
const char hex[16] = "0123456789ABCDEF";
唯一有效的方法
char hex[16] = "0123456789ABCDE"; hex[15] = "F";
是否有任何编译器选项或我可以做些什么来使字符串在 gcc 编译器中不以 null 结尾。这样我就可以制作一个(n)常量数组
最佳答案
不需要编译器选项,它已经非 NUL 终止。该标准规定只有在可以容纳的情况下才应添加 NUL,否则会溢出。可能只是内存中数组后的下一个字节是 \0
§ 6.7.8p14
An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.
关于c++ - gcc 的非空终止字符串编译器选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4348154/