Why can't I have an unsafe volatile pointer, o

2019-07-24 05:44发布

问题:

I wrote a low level audio player using CoreAudio in c# using xamarin.iOS.

In one of the classes, I have two volatile pointers in the following manner:

public unsafe volatile short* readPointer;
public unsafe volatile short* writePointer;

And the entire program compiles and works quite well.

I also set up a Jenkins build machine so it invokes mdtool on my project file to build it in AdHoc mode. However, when I build in this manner, I am getting the following error:

Build complete -- 2 errors, 0 warnings
MixerChannel.cs(21,39) : error CS0677: `MixerChannel.readPointer': A volatile field cannot be of the type `short*'
MixerChannel.cs(22,39) : error CS0677: `MixerChannel.writePointer': A volatile field cannot be of the type `short*'

According to MSDN, I am able to create volatile fields of the following types:

  • Any reference type
  • Any pointer type (in an unsafe context)
  • The types sbyte, byte, short, ushort, int, uint, char, float, bool
  • Enum types based on any of the above types

But this error seems to state otherwise.

The Jenkins build machine is exactly the same I use to build to debug. However, the build process is different: for debugging, I'm using the xamarin build host, and building from a Windows box with Visual Studio 2010. For the Jenkins build, I am using mdtool invoked remotely from the same Window box using plink.

Am I missing something obvious here? I strongly believe that compiler writers are demigods, and therefore any error is almost surely in my own code and not in the compiler.

回答1:

Please refer to this https://bugzilla.xamarin.com/show_bug.cgi?id=23770 bug report and its status.

It appears that the compiler writers, although being demigods, can still make mistakes sometimes (in this case in the mono compiler).

Generally they either quickly correct those mistakes, or zap whoever mentions them with bolts of lightning.

But, you are in luck. This problem is supposed to be fixed in Mono 3.12. So check your version and upgrade.