Path: csiph.com!1.us.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail NNTP-Posting-Date: Fri, 30 Sep 2016 16:09:57 -0500 From: Gareth Owen Newsgroups: comp.lang.c Subject: Re: volatile in struct member References: <87ponl8pxf.fsf@bsb.me.uk> Date: Fri, 30 Sep 2016 22:09:57 +0100 Message-ID: <87wphtt7q2.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:7tfCA5/dkBlRVbwz68PikN0twjM= MIME-Version: 1.0 Content-Type: text/plain Lines: 31 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-Esms9TiVndhHAT2Fb/7E3U3bf3/e72R6+xImQ+Le5kMoDLTwQgJQ5L2eLACt4PLyCiCe+qM3dfXV+xt!Py9kxDjZRsb5fju13pyjfTigg47hxEke/1sAQUHxnJCWzKtslmOb+0OiJVW7K7jUdHQITA== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 1819 Xref: csiph.com comp.lang.c:94335 Ben Bacarisse writes: > But I suspect the question is more about the placement of the keyword. > I'd put the volatile on the object declaration: > > struct small { int i; }; > volatile struct small sm; But one could easily imagine a struct like struct register { volatile int * address; int last_written_value; } void write_reg(struct register*reg,int val) { *reg->address = val; last_written_value = val; } int read_reg(struct register*reg,int val) { return reg->last_written_value; } I wouldn't need to have the cached value marked as volatile (though in a trivial example like this it would make little difference to performance). I've programmed FPGAs with "write only" registers like this.