pointers to Volatile in C#

Chris, thanks for the rapid response. I did not know of IntPtr, but it does not
apply in this case. I really need a pointer to volatile ushort, as the memory is
a 16 bit device. The code I attempted was inside a method-
void someMethod() {
int temp;
unsafe {
volatile ushort* ptr = comRch.GetSomeAddr(); // won't compile with volatile
*ptr = expression; // want fast assignemnt
temp = *ptr;
}
}
Compiler just doesn't like volatile modifiers on pointers, but my reading
of the language spec says it should. Further, I think I need it ! I'm trying
to avoid the time hit of a COM interop call.
bill mccandless

[683 byte] By [billmccandless] at [2007-12-16]
# 1

I retract! You CAN use pointers as fields in an unsafe type, so volatile pointer fields should work, too. Sorry about that, I had never seen that construct but it's actually legal.

Rather, it's the other way round: you can only use volatile on fields, not on local variables. So you'd have to refactor your method into a class and turn the volatile *ptr into a field. The class itself must be marked as unsafe in this case.

ChrisNahr at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# Language...