本文介绍了指针和固定大小的缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
希望可以有人帮帮我.我有以下代码:
Hi guys
Hope someone can help me. I have the following code :
void responseCode (char challenge0,
char challenge1,
char challenge2,
char challenge3,
char challenge4,
char challenge5,
char* response0,
char* response1,
char* response2,
char* response3,
char* response4,
char* response5)
{
char b0, b1, b2, b3, b4, b5;
b0 = byteConv (challenge0, 0);
b1 = byteConv (challenge1, 1);
b2 = byteConv (challenge2, 2);
b3 = byteConv (challenge3, 3);
b4 = byteConv (challenge4, 4);
b5 = byteConv (challenge5, 5);
*response0 = Convert.ToChar((b1 + b2 - b3 + b4 - b5) ^ b0);
*response1 = Convert.ToChar((b2 + b3 - b4 + b5 - b0) ^ b1);
*response2 = Convert.ToChar((b3 + b4 - b5 + b0 - b1) ^ b2);
*response3 = Convert.ToChar((b4 + b5 - b0 + b1 - b2) ^ b3);
*response4 = Convert.ToChar((b5 + b0 - b1 + b2 - b3) ^ b4);
*response5 = Convert.ToChar((b0 + b1 - b2 + b3 - b4) ^ b5);
}
但是我在这条线上出现错误:char * response0,
读取错误:指针和固定大小的缓冲区只能在不安全的上下文中使用.
如果有人可以帮助,它将被申请
在此先感谢
However I get an error on this line : char* response0,
The error reads : Pointers and fixed size buffers may only be used in an unsafe context.
If anyone can assist it will be appriciated
Thanks in advance
推荐答案
private unsafe void responseCode (char challenge0,...
{
...
}
您还必须在项目属性中指定允许不安全的代码".
这是因为在C#中实际上不建议使用指针-在99.9999%的时间内,您不需要使用指针,因为引用可以完成工作.
You also have to specify "Allow unsafe code" in the project properties.
This is because pointers are really discouraged in C# - 99.9999% of the time, you do not need to use them, as references will do the job.
这篇关于指针和固定大小的缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!