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

问题描述

我已经得到了我想要追加和结果应该被分配到一个LHS变量两个C字符串。我看到了一个静态初始化code,如:

I've got two C strings that I want to append and result should be assigned to an lhs variable. I saw a static initialization code like:

的char * OUT =愿上帝保佑;

输出真的五一GodBless你上打印出来。我理解这个结果可能是一些不确定的行为输出。

The output was really "May GodBless You" on printing out. I understand this result can be output of some undefined behaviour.

在code竟是生产,从来不给错误的结果。而且它不像我们只在一个地方有这样的语句。它可以在很稳定code的多个地方看到并用于形成SQL查询。

The code was actually in production and never gave wrong results. And it was not like we had such statements only at one place. It could be seen at multiple places of very much stable code and were used to form sql queries.

请问C标准允许这样的串联?

Does C standard allow such concatenation?

推荐答案

是的,这是保证。

http://en.wikipedia.org/wiki/C_syntax#String_literal_concatenation:

相邻字符串文字
  在编译时级联;这个
  允许长字符串被分裂了
  多行,并且还允许弦
  从C preprocessor导致文字
  定义和宏附加到
  在编译时字符串

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

08-05 08:08