0

Compiling a VS 2010 c# project (.NET 4.0, any CPU, allow unsafe code = checked) we are getting a variety of compile errors as below:

  1. Operator '*' cannot be applied to operands of type 'System.IntPtr' and 'int'

  2. Constant value '325486741' cannot be converted to a 'int' (use 'unchecked' syntax to override)

  3. Cannot convert type 'string' to 'char*'

  4. Cannot implicitly convert type 'long' to 'byte*'. An explicit conversion exists (are you missing a cast?)

  5. Invalid expression term 'ref'

All these are occurring in 'unsafe' methods.

How to resolve these ?

1 Answer 1

2

We'd need to see your code, but I'd say that the "unsafe" part is irrelevant to the errors, since those seem to be problems with casting and such.

Here's some info that might help:

  1. Operator '*' cannot be applied to operands of type 'System.IntPtr' and 'int'

Try casting to an int or long first.

  1. Constant value '325486741' cannot be converted to a 'int' (use 'unchecked' syntax to override)

Try using unchecked((int)variable).

  1. Cannot convert type 'string' to 'char*'

Try using:

 fixed (char* pChar = my_string) { ... }
  1. Cannot implicitly convert type 'long' to 'byte*'. An explicit conversion exists (are you missing a cast?)

Try casting: byte* pB = (byte*)value;

  1. Invalid expression term 'ref'

I can't say much about this one without the code.

Sign up to request clarification or add additional context in comments.

6 Comments

it was using fixed (char* mystr = ((char*) mydata)). removing (char*) made this error go atleast. thnx.
Constant value '-1' cannot be converted to a 'uint' (use 'unchecked' syntax to override) ((uint) (-1)) >> ((10 - i) << 5)
Invalid expression ')' for int i = ((ref int) myPtr) myPtr is of type byte*
What about : Operator '+' cannot be applied to operands of type 'byte*' and 'byte*'
Well, you can't add two byte* s... what was your intention?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.