What is volatile reference ?

D

dwaach

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
 
E

Earl Purple

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

dwaach

Earl said:
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
 
B

Ben Pope

dwaach said:
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
 
D

dwaach

Ben said:
dwaach said:
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



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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top