[英]Defining Binary Macros in C++
Can someone explain why the following error happens: 有人可以解释为什么发生以下错误:
#define bla "\xA"
char a [2] = {0};
memcpy (a,bla,1); // a[0] = 0x0a <- Correct
//a[1] = bla; // '=' : cannot convert from 'const char [2]' to 'char'
Thanks, 谢谢,
RM R M
The types are different: a[1] is a char and "\\xA" is an array of char. 类型不同:a [1]是一个字符,“ \\ xA”是一个字符数组。
In C++ and C anything enclosed in double quotes (including nothing) is an array of char. 在C ++和C中,用双引号引起来的所有内容(包括所有内容)都是char数组。
Try: 尝试:
#define bla '\xA'
Although that will stop the memcpy
working. 虽然这将停止
memcpy
工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.