AnsweredAssumed Answered

Guarantees for volatile qualifier

Question asked by JWellbelove on Jul 12, 2012
Latest reply on Jul 13, 2012 by StuartS

After following a discussion on LinkedIn about the differing code generated by compilers for certain expressions involving a volatile destination, I was wondering how how the VisualDSP++ compiler handles the following.

 

volatile int a;

int b;

int c;

 

c = (a = b);

 

It appears that the current standard is a bit non-committal about how the value of the expression (a = b) is derived.

It seems that some compilers will store the value of 'b', copy it to 'a', and return the value.

There is one read from 'b' and one write to 'a'.

 

Others, such as GCC, will copy 'b' to 'a' and then read 'a' as the value of the expression.

In this case there will be one read from 'b', one write to 'a' and then one read from 'a'.

 

As the 'a' is a volatile, the first method would seem more 'correct'; more so if 'a' were to be a pointer to a write-only register.

 

How does VisualDSP++ handle this?

Outcomes