On Friday 11 June 2010 23:31:57 Dag-Erling Smørgrav wrote: > Tijl Coosemans <t...@coosemans.org> writes: >> Dag-Erling Smørgrav <d...@des.no> writes: >>> #define FORCE_ASSIGN(type, var, value) \ >>> *(volatile type *)&(var) = (value) >> memset can be optimised away as well. The only way is to declare >> those variables volatile. > > Assigning through a volatile pointer, as in FORCE_ASSIGN(), also > works, even if the variable itself is not volatile.
Just thought of problem with this macro when var is a pointer. Then volatile applies to the referenced memory and not the variable. So you should move the volatile keyword, like so: #define FORCE_ASSIGN(type, var, value) \ *(type volatile *)&(var) = (value) And if you can use GNU extensions this can be simplified to: #define FORCE_ASSIGN(var, value) \ *(typeof(var) volatile *)&(var) = (value) _______________________________________________ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"