473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Q: volatile struct elements or entire struct?

If I have a structure that may point to a volatile "region (e.g. device)"
or a context in memory what would be the best way to use the volatile
keyword?

E.g.

a) volatile on struct objects

struct Foo
{
unsigned char command;
unsigned char status;
unsigned long baseAddr;
unsigned long addrRange;
}

volatile struct Foo *pDevFoo = (some dev. address);
struct Foo hostFoo;
- or -
b) volatile on struct members

struct Foo
{
volatile unsigned char command;
volatile unsigned char status;
volatile unsigned long baseAddr;
volatile unsigned long addrRange;
}

struct Foo *pDevFoo = (some dev. address);
struct Foo hostFoo; /* live with extra accesses */
Does my use of volatile in a) even do what I intend? That is, make
accesses to the device volatile?

Thanks.

--
- Mark ->
--
Nov 14 '05 #1
3 8309
In article <news:Xn********************************@130.133.1 .4>
Mark A. Odell <od*******@hotmail.com> wrote:

[which of these should one use:]
a) volatile on struct objects

struct Foo {
unsigned char command;
unsigned char status;
unsigned long baseAddr;
unsigned long addrRange;
}

volatile struct Foo *pDevFoo = (some dev. address);
struct Foo hostFoo;
This is the version I prefer, for several reasons, the most valid :-)
being the one shown right here in your example: you can make a
non-volatile version of it.
b) volatile on struct members

struct Foo
{
volatile unsigned char command;
volatile unsigned char status;
volatile unsigned long baseAddr;
volatile unsigned long addrRange;
}

struct Foo *pDevFoo = (some dev. address);
struct Foo hostFoo; /* live with extra accesses */

Does my use of volatile in a) even do what I intend? That is, make
accesses to the device volatile?


Yes. Both methods work (provided, of course, that your implementation's
definition of "volatile" does what you need in the first place --
if not, neither method works anyway!).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #2
Chris Torek <no****@torek.net> wrote in
news:ci*********@news4.newsguy.com:
In article <news:Xn********************************@130.133.1 .4>
Mark A. Odell <od*******@hotmail.com> wrote:

[which of these should one use:]
a) volatile on struct objects

struct Foo {
unsigned char command;
unsigned char status;
unsigned long baseAddr;
unsigned long addrRange;
}

volatile struct Foo *pDevFoo = (some dev. address);
struct Foo hostFoo;
This is the version I prefer, for several reasons, the most valid :-)
being the one shown right here in your example: you can make a
non-volatile version of it.


Excellent.
b) volatile on struct members

struct Foo
{
volatile unsigned char command;
volatile unsigned char status;
volatile unsigned long baseAddr;
volatile unsigned long addrRange;
}

struct Foo *pDevFoo = (some dev. address);
struct Foo hostFoo; /* live with extra accesses */

Does my use of volatile in a) even do what I intend? That is, make
accesses to the device volatile?


Yes. Both methods work (provided, of course, that your implementation's
definition of "volatile" does what you need in the first place --
if not, neither method works anyway!).


Oh it does, this has been heavily verified. Cross-compilers tend to this
as one my hope for.

Thanks Chirs.

--
- Mark ->
--
Nov 14 '05 #3
"Mark A. Odell" <od*******@hotmail.com> wrote in
news:Xn********************************@130.133.1. 4:

Oh it does, this has been heavily verified. Cross-compilers tend to this
as one my hope for.

^^
might

--
- Mark ->
--
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

258
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
33
by: Chris Fogelklou | last post by:
What is wrong with the above? Don't worry, I already know (learned my lesson last week.) It is for the benefit of our resident compiler guru who seems to think you need the cast. I thought it...
0
by: Peter Demeyer | last post by:
I have this problem: 'pno' is a pointer to a struct of type PRINTER_NOTIFY_OPTIONS. This struct is holding another struct called 'not' (of type PRINTER_NOTIFY_OPTIONS_TYPE) which contains a couple...
3
by: Ben Schwehn | last post by:
If I pin a member of a garbage collected structure, can I safely assume that the entire struct is pinned? I use something like that: (new whidbey syntax, but that shouldn't make a difference): ...
3
by: monkeydragon | last post by:
hi, i am making a struct within a struct like this.. struct upper { struct lower{ BYTE* row; UINT width_row; } }
5
by: karthikbalaguru | last post by:
Hi, struct sky { int stars; struct ocean *oceanptr; }; struct ocean { int waves; struct sky *skyptr;
3
by: bernd | last post by:
Hi folks, the code below "runs" with the following message: Before structure assignment Bus Error(coredump) What I am trying to do is to define an "outer" structure containing an inner one...
1
by: joohoo | last post by:
here is my question. I have two structs, one holds a bunch of info in it. it is passed to the function by reference and i want to paste it into another struct as a member of it. ex.
5
by: emmanuel.rivoire | last post by:
Hello, I spent almost a week to be able to embed Python within my C++ game engine. I wrote a mini-tutorial of what I was able to do so far here :...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.