gcc的非空结尾的字符串编译器选项 [英] Non null-terminated string compiler option for gcc

查看:123
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆