C ++多字符字面 [英] C++ multicharacter literal

查看:143
本文介绍了C ++多字符字面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道,C和C ++中的<一个href=\"http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=%2Fcom.ibm.vacpp6m.doc%2Flanguage%2Fref%2Fclrc02ccon.htm\"><$c$c>multicharacter文字 :不是'C',而是'tralivali(类型(在C型的 INT 的和的用C字符的++的)的 INT 的!)

I didn't know that C and C++ allow multicharacter literal: not 'c' (of type int in C and char in C++), but 'tralivali' (of type int!)

enum
{
    ActionLeft = 'left',
    ActionRight = 'right',
    ActionForward = 'forward',
    ActionBackward = 'backward'
};

标准说:

C99 6.4.4.4p10的价值
  含整型字符常量
  多个字符(例如,AB),
  或包含字符或逃生
  序列不映射到一个
  单字节执行字符,是
  实现定义。

C99 6.4.4.4p10: "The value of an integer character constant containing more than one character (e.g., 'ab'), or containing a character or escape sequence that does not map to a single-byte execution character, is implementation-defined."

我发现,他们被广泛应用于 C4引擎。不过,我想他们是不是安全,当我们谈论平台的影响无关序列化。大公可也令人困惑,因为像字符串。那么,什么是使用的多字符文字的范围,它们是什么东西有用吗?他们是在C ++只是为了与C code兼容性?它们是否被认为是一个坏的特征,因为的转到的运算符或不?

I found they are widely used in C4 engine. But I suppose they are not safe when we are talking about platform-independend serialization. Thay can be confusing also because look like strings. So what is multicharacter literal's scope of usage, are they useful for something? Are they in C++ just for compatibility with C code? Are they considered to be a bad feature as goto operator or not?

推荐答案

我不知道这是怎么广泛使用,但实现定义是一个很大的红旗给我。据我所知,这可能意味着实现可以选择忽略你的角色名称,只是正常的分配值递增,如果它想要的。它可能会做一些更好,但你不能依赖于跨编译器(甚至是编译器版本)的行为。至少有GOTO有predictable(如不良的)行为...

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.

编辑:在实现定义,

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.

也...

未定义 - 的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.

这篇关于C ++多字符字面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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