且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C 和 C++ 中的多字符文字

更新时间:2021-09-22 01:31:33

我不知道它的使用范围有多广,但是实现定义"对我来说是一个很大的危险信号.据我所知,这可能意味着实现可以选择忽略您的字符名称,并根据需要仅分配正常的增量值.它可能会做一些更好"的事情,但你不能依赖编译器(甚至编译器版本)之间的这种行为.至少转到"具有可预测(如果不受欢迎)的行为...

I don't know how extensively this is used, but "implementation-defined" is a big red-flag to me. As far as I know, this could mean that the implementation could choose to ignore your character designations and just assign normal incrementing values if it wanted. It may do something "nicer", but you can't rely on that behavior across compilers (or even compiler versions). At least "goto" has predictable (if undesirable) behavior...

无论如何,这是我的 2c.

That's my 2c, anyway.

关于实现定义":

来自 Bjarne Stroustrup 的 C++ 词汇表:

实现定义 - C++ 语义的一个方面,为每个实现定义,而不是在标准中为每个实现指定.一个例子是 int 的大小(它必须至少为 16 位,但可以更长).尽可能避免实现定义的行为.另见:未定义.TC++PL C.2.

implementation defined - an aspect of C++'s semantics that is defined for each implementation rather than specified in the standard for every implementation. An example is the size of an int (which must be at least 16 bits but can be longer). Avoid implementation defined behavior whenever possible. See also: undefined. TC++PL C.2.

还有...

undefined - C++ 语义的一个方面,不需要合理的行为.一个示例是取消引用值为零的指针.避免未定义的行为.另见:实现定义.TC++PL C.2.

undefined - an aspect of C++'s semantics for which no reasonable behavior is required. An example is dereferencing a pointer with the value zero. Avoid undefined behavior. See also: implementation defined. TC++PL C.2.

我相信这意味着评论是正确的:它至少应该编译,尽管没有指定超出的任何内容.还要注意定义中的建议.

I believe this means the comment is correct: it should at least compile, although anything beyond that is not specified. Note the advice in the definition, also.