为什么我可以通过这样的字符串参数?这种样式安全吗?
Why can I pass a string parameter like this? Is this style safe?
我将两个字符串作为Xcode中的一个参数和使用C 传递。我在Xcode中尝试了此操作,并且可以使用。但是这在所有平台上都安全吗?
#include <iostream>
void log_person(const char* name_and_number){
printf("name and number : %s.n", name_and_number);
}
int main(int argc, const char * argv[]) {
log_person("jim" "123456789");
return 0;
}
您正在传递一个字符串。这个
"Foo" "Bar"
完全等同于
"FooBar"
所以您的呼叫与
相同log_person("jim123456789");
这是标准的C ,因此"安全"也是如此。在任何符合的实施中。参见C 11中的 2.14.5/13 标准:
2.14.5字符串文字
...
13 在翻译阶段6(2.2)中,相邻的字符串文字被串联....
相关文章:
- C++中的高效循环缓冲区,它将被传递给C样式数组函数参数
- 将有状态的 lambda 传递到 C 样式函数中,而无需上下文参数
- 解压缩 C 样式数组以及C++中的参数包
- C++ C 样式数组作为语法错误的参数
- 限制C++中允许的模板参数是否被认为是不良样式?
- C 样式将此或shared_from_this作为函数参数
- 如何将初始值设定项与右值引用参数一起使用 // 为什么不能使用另一个 C 样式数组变量初始化 C 样式数组
- Qt样式表和"一个参数"问题
- 为什么我可以通过这样的字符串参数?这种样式安全吗?
- C 函数对象模板参数扣除样式
- 具有列表参数C++11/C++14样式的求和函数
- C++,哪种参数样式更好,通过复制还是通过常量引用
- C/C++样式--修改函数参数
- C++样式:在构造函数主体中使用参数或成员
- 向 C 样式可变参数列表添加额外的参数
- C++ 传递 C 样式字符串作为参数
- 构造函数参数样式
- 为通过引用设置参数的函数命名的样式
- CreateWindow()样式参数被忽略
- 函数调用参数中的构造函数样式转换