By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 2,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

What is volatile reference ?

P: n/a
Hi,

I have something like.
struct X {};

X ox;
X* pox=&ox;

X*& volatile r =pox;

volatile X*& s =pox;

Is 'r' a volatile reference, or 's' is volatile reference,

I need this for decoding the expression
T*VQ&

where T-> Object Type
VQ-> either volatile or empty.

Help
Dwaach

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
X*& volatile appears to make no sense. Just as X*& const makes no
sense. You cannot have a & const or a & volatile, because a & cannot be
reseated to refer to another object (thus another thread inside this
function could not modify it to point to a different object).

The volatile on s refers to the X not to the pointer. So here another
thread might modify the X by calling a non-const method on it (or
modifying one of its members).

Jul 23 '05 #2

P: n/a


Earl Purple wrote:
X*& volatile appears to make no sense. Just as X*& const makes no
sense. You cannot have a & const or a & volatile, because a & cannot be
reseated to refer to another object (thus another thread inside this
function could not modify it to point to a different object).

The volatile on s refers to the X not to the pointer. So here another
thread might modify the X by calling a non-const method on it (or
modifying one of its members).


So far so good..
Then what does
T*VQ&,
signify

if I decode it ,
its like
struct X* volatile &
is the volatile keyword on * to X..or it is to X or to &

AFAIK, volatile is on pointer,
but it dosent make sense, as T is itself some uer data type which may
or may not be CV qualified,
so things have mixed again...

Help !
Dwaach

Jul 23 '05 #3

P: n/a
dwaach wrote:

Earl Purple wrote:
X*& volatile appears to make no sense. Just as X*& const makes no
sense. You cannot have a & const or a & volatile, because a & cannot be
reseated to refer to another object (thus another thread inside this
function could not modify it to point to a different object).

The volatile on s refers to the X not to the pointer. So here another
thread might modify the X by calling a non-const method on it (or
modifying one of its members).

So far so good..
Then what does
T*VQ&,
signify


Imagine:

int * const & x; // x is a reference to a const pointer to int
if I decode it ,
its like
struct X* volatile &
is the volatile keyword on * to X..or it is to X or to &

AFAIK, volatile is on pointer,
Yes.
but it dosent make sense, as T is itself some uer data type which may
or may not be CV qualified,
so things have mixed again...


#include <string>
using namespace std;

typedef unsigned char T;

#define VQ volatile

int main(int argc, char* argv[])
{
T*VQ a = 0; // a is a volatile pointer to a T with a value of 0
T*VQ& b = a; // b is a reference to a volatile...

T VQ * VQ c; // c is a volatile pointer to a volatile T
T VQ * VQ& d = c; // You get the idea.

return 0;
}

Ben
--
I'm not just a number. To many, I'm known as a String...
Jul 23 '05 #4

P: n/a
Ben Pope wrote:
dwaach wrote:

Earl Purple wrote:
X*& volatile appears to make no sense. Just as X*& const makes no
sense. You cannot have a & const or a & volatile, because a & cannot be
reseated to refer to another object (thus another thread inside this
function could not modify it to point to a different object).

The volatile on s refers to the X not to the pointer. So here another
thread might modify the X by calling a non-const method on it (or
modifying one of its members).

So far so good..
Then what does
T*VQ&,
signify


Imagine:

int * const & x; // x is a reference to a const pointer to int
if I decode it ,
its like
struct X* volatile &
is the volatile keyword on * to X..or it is to X or to &

AFAIK, volatile is on pointer,


Yes.
but it dosent make sense, as T is itself some uer data type which may
or may not be CV qualified,
so things have mixed again...


#include <string>
using namespace std;

typedef unsigned char T;

#define VQ volatile

int main(int argc, char* argv[])
{
T*VQ a = 0; // a is a volatile pointer to a T with a value of 0
T*VQ& b = a; // b is a reference to a volatile...

T VQ * VQ c; // c is a volatile pointer to a volatile T
T VQ * VQ& d = c; // You get the idea.

return 0;
}

Ben
--
I'm not just a number. To many, I'm known as a String...


Hey Ben,

Thanks a lot.
Your superb xample made things very clear.

Hope to discuss some more stuff in future.
Bye and thanks again.
Dwaach

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.