Skip to content

Missing a way to work around CS0677 #45367

@rindlespot

Description

@rindlespot

Type of issue

Missing information

Description

If you are trying to declare a long (as the sample text does), using the volatile qualifier gets rejected because the (eventual) hardware platform may not support atomic access to long. But using nint allows platforms that do support such access the ability to work around this. By definition the compiler knows that it can atomically access things of size nint.

Which means that a 'potential fix' for CS0677 might be to change the type from 'long' to nint. Obviously not a solution for all situations, but it sure helped me, and was more technically correct for my situation anyway. Seems like a trick worth mentioning.

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0677?f1url=%3FappId%3Droslyn%26k%3Dk(CS0677)

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/misc/cs0677.md

Document Version Independent Id

e2cad238-58cd-e146-f3b6-5ceeefbc0db9

Platform Id

a744c9c9-8bb6-1fd2-6179-457f36514661

Article author

@BillWagner

Metadata

  • ID: 649176da-1a4f-84f9-9329-8f9d81a656fd
  • PlatformId: a744c9c9-8bb6-1fd2-6179-457f36514661
  • Service: dotnet-csharp
  • Sub-service: errors-warnings

Related Issues


Associated WorkItem - 482966

Metadata

Metadata

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.dotnet-csharp/svcerrors-warnings/subsvcokr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions