Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #94338

Re: volatile in struct member

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: volatile in struct member
Date 2016-09-30 22:24 +0100
Organization A noiseless patient Spider
Message-ID <87a8ep6py2.fsf@bsb.me.uk> (permalink)
References <dc811de3-cad5-4f57-b68d-dd8b0252e507@googlegroups.com> <aa598ef6-1a14-443d-b1f7-50a20cecef0c@googlegroups.com> <87ponl8pxf.fsf@bsb.me.uk> <87wphtt7q2.fsf@gmail.com>

Show all headers | View raw


Gareth Owen <gwowen@gmail.com> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> 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;
> }

I don't think anyone has been questioning the validity of pointing to
volatile data.

> 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.

I think I'm missing your point.  The fact that you are writing
hypothetically ("I wouldn't need") makes it particularly tricky (for me,
at least).

-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

volatile in struct member Thiago Adams <thiago.adams@gmail.com> - 2016-09-30 04:52 -0700
  Re: volatile in struct member Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-09-30 05:50 -0700
    Re: volatile in struct member Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-30 14:42 +0100
      Re: volatile in struct member Gareth Owen <gwowen@gmail.com> - 2016-09-30 22:09 +0100
        Re: volatile in struct member Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-30 22:24 +0100
  Re: volatile in struct member Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-30 14:29 +0100
    Re: volatile in struct member David Brown <david.brown@hesbynett.no> - 2016-09-30 16:22 +0200
      Re: volatile in struct member Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-30 15:51 +0100
        Re: volatile in struct member David Brown <david.brown@hesbynett.no> - 2016-09-30 17:07 +0200
    Re: volatile in struct member Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-08 15:48 -0700
  Re: volatile in struct member David Brown <david.brown@hesbynett.no> - 2016-09-30 15:36 +0200
    Re: volatile in struct member Thiago Adams <thiago.adams@gmail.com> - 2016-09-30 06:47 -0700
      Re: volatile in struct member James Kuyper <jameskuyper@verizon.net> - 2016-09-30 12:53 -0400
        Re: volatile in struct member supercat@casperkitty.com - 2016-09-30 10:18 -0700
          Re: volatile in struct member raltbos@xs4all.nl (Richard Bos) - 2016-09-30 20:57 +0000
            Re: volatile in struct member supercat@casperkitty.com - 2016-09-30 14:46 -0700
        Re: volatile in struct member Thiago Adams <thiago.adams@gmail.com> - 2016-09-30 10:22 -0700
          Re: volatile in struct member jameskuyper@verizon.net - 2016-09-30 14:08 -0700

csiph-web