A
Antonio
I'm developing the firmware for a slave in a comunication channel. Now
there is certain information (namely the addresses of the slave and the
master) that must be changeable while the device is up and operating.
The obvious choice is to store the addresses in some variable. But I
would like to prevent unintentional changes in those variables so I
thought of doing the following stuff:
File addresses.c :
char masterAddress;
void changeMasterAddress (char newValue) {
masterAddress = newValue;
}
Another file:
extern const volatile char masterAddress;
extern void changeMasterAddress (char newValue);
I've compiled this with gcc and it works as expected. The compiler
issues warnings if I try to assign a value to masterAddress outside
addresses.c, and I can still change its value with changeMasterAddress
anywhere in the code.
Finally my questions:
1.- Is this behaviour standard?
2.- Is the volatile keyword needed in the declaration? I thought of
placing it to prevent the compiler from optimizing multiple accesses to
a read-only variable (as seen in the rest of the files).
Thanks in advance.
there is certain information (namely the addresses of the slave and the
master) that must be changeable while the device is up and operating.
The obvious choice is to store the addresses in some variable. But I
would like to prevent unintentional changes in those variables so I
thought of doing the following stuff:
File addresses.c :
char masterAddress;
void changeMasterAddress (char newValue) {
masterAddress = newValue;
}
Another file:
extern const volatile char masterAddress;
extern void changeMasterAddress (char newValue);
I've compiled this with gcc and it works as expected. The compiler
issues warnings if I try to assign a value to masterAddress outside
addresses.c, and I can still change its value with changeMasterAddress
anywhere in the code.
Finally my questions:
1.- Is this behaviour standard?
2.- Is the volatile keyword needed in the declaration? I thought of
placing it to prevent the compiler from optimizing multiple accesses to
a read-only variable (as seen in the rest of the files).
Thanks in advance.