Re: A basic question question about volatile use



On Thu, 31 Jul 2008 05:23:23 GMT, Ark Khasin
<akhasin@xxxxxxxxxxxxxxxxxxxx> wrote:

I have a memory-mapped peripheral with a mapping like, say,
struct T {uint8_t read, write, status, forkicks;};

If you want to insure that there is no padding between the four
members, change it to {uint8_t x[4];}. If you like, you can add
macros of the form
#define READ x[0]
#define WRITE x[1]
so that references to the members are mnemonically meaningful.


If I slap a volatile on an object of type struct T, does it guarantee
that all accesses to the members are byte-wide, or is the compiler free
to read or read-modify-write in any data width it chooses?

This is really a system specific issue. I doubt if volatile makes a
difference. A machine may perform all memory accesses in "word" sized
blocks and extract the relevant bytes from internal registers.

I would expect that since this peripheral works on your system that
your system supports byte accesses. I would further expect that
anyone writing a compiler for this system would do so also.

But you asked for a guarantee. The best we can offer is probably. If
your compiler has a newsgroup or a tech support site, that would be
the place to ask.


Is slapping a volatile on each member of the struct definition any
different? better? worse?

I don't see how it could hurt and it does emphasize your intent.

--
Remove del for email
.



Relevant Pages