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 4 5783
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).
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
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...
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Michael Brown |
last post by:
I've got some code that looks somewhat like this:
typedef struct TAG_STREAMDATA
{
// Lots of stuff in here ...
double param1, param2;
} STREAMDATA;
|
by: Mantorok Redgormor |
last post by:
does volatile really inhibit side effects?
that is the rules for sequence points and side effects do not apply to
volatile objects?
--
nethlek
|
by: Eric |
last post by:
I have some questions about the volatile keyword...
1) If I use the volatile keyword with a reference type such as a class like
so:
public volatile UserTotals totals = new UserTotals();
Are...
|
by: titan nyquist |
last post by:
Can you make volatile structures in C#?
I have a static class, to have "global" variables. This allows the
whole program to see them. I make them "volatile" to avoid multi-
threading accessing...
|
by: Samuel R. Neff |
last post by:
When is it appropriate to use "volatile" keyword? The docs simply
state:
"
The volatile modifier is usually used for a field that is accessed by
multiple threads without using the lock...
|
by: George2 |
last post by:
Hello everyone,
Through myself study and previous discussion here, I share the
conclusion here that,
if some object is synchronized (mutex, critical section, etc.), there
is no need to add...
|
by: S James S Stapleton |
last post by:
Is volatile necessary anymore? I have a two-thread piece of code I've been
testing to figure out what volatile does (fairly simple code, uses
pthreads). I have an update thread (variables passed as...
|
by: Gestorm |
last post by:
Hi all, I found a macro "USE_VAR" in the code of bash-3.2 as
follows:
/*file: bash-3.2/shell.c*/
344 USE_VAR(argc);
345 USE_VAR(argv);
346 USE_VAR(env);
347 USE_VAR(code);
348 ...
|
by: Mark Salsbery [MVP] |
last post by:
I have an member variable (int) that is accessed by multiple threads using
Interlocked.Increment(), Interlocked.Decrement(), and read directly.
Using volatile gives me "CS0420: a reference to a...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |