LWN.net Logo

BSD Dissatisfied with gcc... why?

BSD Dissatisfied with gcc... why?

Posted Nov 19, 2008 14:36 UTC (Wed) by dgm (subscriber, #49227)
In reply to: BSD Dissatisfied with gcc... why? by etienne_lorrain@yahoo.fr
Parent article: pcc seeks contributions to reach 1.0 milestone

> the basic use of volatile (register mapped) integers

Wrong. I think you were thinking of the "register" keyword.
"Volatile" means that the contents of a variable can be changed externally at any time. Think, for instance, of a memory mapped hardware register. Basically it instructs the compiler to avoid certain optimizations based on knowledge of the previous value, and forces it to read it every time.


(Log in to post comments)

BSD Dissatisfied with gcc... why?

Posted Nov 19, 2008 20:57 UTC (Wed) by nix (subscriber, #2304) [Link]

In particular, 'volatile' is still useful. 'register' is, basically, not,
with the single rare exception of global register variables (a GCC
extension).

BSD Dissatisfied with gcc... why?

Posted Nov 20, 2008 10:34 UTC (Thu) by etienne_lorrain@yahoo.fr (guest, #38022) [Link]

> > the basic use of volatile (register mapped) integers
> Wrong. I think you were thinking of the "register" keyword.

No, I was and am still talking of "volatile".
The problem is that the C++ standard treats all attributes the same way, and gives examples with "const".
I do understand that to overwrite the "const" attribute, I need to do a dirty cast to non-const, but the basic use of volatile is to copy them into standard variables, at a controled place of the software:

volatile unsigned ethernet_status;
/* -> address of ethernet_status defined in the linker file */
int fct(void) {
unsigned status = ethernet_status; // single read of "ethernet_status"
return ((status & 1) || ((status & 2) ^ (status & 4)));
}

Now tell me how to put ethernet_status and fct() into a class and compile without warning and without casting ethernet_status to non-volatile...

But the worst for me is still considering a volatile structure of bitfields as a structure of volatile bitfields, even if I see no problem to consider a constant structure of bitfields as a structure of constant bitfields...
For instance:
volatile struct color_s { char red, green, blue, transparent; } volcolor;
int fct (void) {
struct color_s color = volcolor;
return color.red == color.blue;
}
Because volcolor is considered as a structure of volatile fields, volcolor is read twice (two byte access) when optimising.

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds