How to interface to a C struct with volatile variables?

Ben Davis entheh at cantab.net
Sat Feb 16 06:13:30 PST 2013


On 16/02/2013 03:54, Charles Hixson wrote:
> Does D have an equivalent to the C marking of volatile?
>
> Currently I'm just going to try removing all variables from the struct,
> as it's never declared in D or accessed from within D, and I just want
> to avoid cast(void*)s, but I may need to access something like this
> sometime in the future.

In your case, I think you can declare opaque structs in D:

struct S;	//Opaque
struct S { ... }	//Not opaque

As for 'volatile', there's some info at 
http://dlang.org/deprecate.html#volatile about how it used to be 
available for marking statements as 'do not optimise field accesses'. 
The corrective action listed there is to use 'synchronized' instead. So 
probably your best bet is to use 'synchronized' blocks wherever you 
access the variables that you know are meant to be volatile.

Hope that helps :)


More information about the Digitalmars-d-learn mailing list