当存在修饰符(L,u8等)时,使用相邻字符串字面串联会发生什么 [英] What happens with adjacent string literal concatenation when there is a modifier(L, u8, etc.)

查看:521
本文介绍了当存在修饰符(L,u8等)时,使用相邻字符串字面串联会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它在C和C ++中有效,因为预处理器或编译器将
连接到相邻的字符串文字。

It is valid in C and C++ to break a string literal because the preprocessor or the compiler will concatenate adjacent string literals.

const char *zStr = "a" "b"; // valid

当字符串文字以 L (宽字符), u (UTF-16), U code> u8 (UTF-8)和原始字符串文字( Rfoo(这是一个带双引号的原始字符串文字)foo code>)?

What happens when string literals are prefixed with L (wide characters), u (UTF-16), U (UTF-32), u8 (UTF-8), and raw string literals (R"foo(this is a "raw string literal" with double quotes)foo")?

例如,以下是允许的:

const wchar_t *zStr = L"a" "b"; // valid?


推荐答案

在C ++ 0x中, [lex.string] / p13:

In C++0x your example is valid according to [lex.string]/p13:


...如果一个字符串文字没有
encoding-prefix,作为
的字符串字面量与另一个操作数相同的
encoding-prefix。
...

... If one string literal has no encoding-prefix, it is treated as a string literal of the same encoding-prefix as the other operand. ...

在C ++ 03中,这个部分说这个代码有未定义的行为:

In C++03 this same section said that this code had undefined behavior:


...如果一个窄字符串文本标记
与一个宽字符串文字
标记相邻,则行为是未定义的。 ...

... If a narrow string literal token is adjacent to a wide string literal token, the behavior is undefined. ...

这篇关于当存在修饰符(L,u8等)时,使用相邻字符串字面串联会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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