Click here to Skip to main content
15,040,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

Hope someone can help me. I have the following code :
C#
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);
                               }

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
Posted
Updated 6-Feb-12 21:28pm
v2
Comments
zyck 7-Feb-12 3:21am
   
are you using c++?
asterisk is represent pointers in c++

removing * to char,response then build
   
What C++? Forget it. Tagged is .NET. It could be C# or C++/CLI.
--SA
   
Why?
--SA

In C#, you can only use pointers when you are in an unsafe method:
C#
private unsafe void responseCode (char challenge0,...
   {
   ...
   }
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.
   
First of all, you should allow unsafe; this is the property of the project.
When you do it, use unsafe statement:

http://msdn.microsoft.com/en-us/library/chfa2zb8%28v=vs.100%29.aspx[^].

Study this tutorial:
http://msdn.microsoft.com/en-us/library/aa288474%28v=vs.71%29.aspx[^].

Finally, ask yourself: why are you trying to use pointer? Usually, this is needed for interoperation with some unmanaged code, and in much more rare cases, for performance reasons.

—SA
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900