gcc的非空结尾的字符串编译器选项 [英] Non null-terminated string compiler option for gcc
问题描述
原来,这只是另一种情况下,C ++不是C布鲁斯
turns out this is just another case of "c++ is not c blues"
我要什么
const char hex[16] = "0123456789ABCDEF";
这是工作的唯一的事
char hex[16] = "0123456789ABCDE"; hex[15] = "F";
是否有任何编译器选项或东西我可以做,使字符串gcc编译NOT NULL终止。这样我可以做一个(n)的常量数组
are there any compiler options or something I can do to make strings not null terminated in the gcc compiler. so that I can make a(n) constant array
推荐答案
无需编译器选项,它的已的非NUL终止。该标准说,一个NUL只应增加,如果能适应,否则这将是一个溢出。这可能只是在内存中的下一个字节过去阵列是 \\ 0
No need for a compiler option, it's already non-NUL terminated. The standard says a NUL should only be added if it can fit, otherwise it would be an overflow. It may just be that the next byte in memory past your array is \0
&教派; 6.7.8p14 搜索结果
字符数组
类型可以由一个字符被初始化
字符串,可选
大括号括起来。字符串的连续字符
文字(的包括
终止空字符,如果有房的或如果数组是
未知大小)初始化
的数组的元素
§ 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.
这篇关于gcc的非空结尾的字符串编译器选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!