struct FOO{
int a;
int b;
int c;
};
volatile struct FOO foo;
int main(void)
{
foo.a = 10;
foo.b = 10;
foo.c = 10;
struct FOO test = foo;
return 0;
}
This won't compile, because
struct FOO test = foo;
generates an error:
error: binding reference of type 'const FOO&' to 'volatile FOO' discards qualifiers
How can I copy a volatile struct
into another struct
in C++ (before C++11)?
Many people suggested to just delelte volatile, but I can't do that in that case, because I want to copy the current SPI-Reg setttings inside a μC and this is declared volatile by the manufacturer headers. I want to copy those settings, because the manufactuerer also provides an Library to use the SPI for EnDat-Communication, and I don't have access to the source-code. Since I have to change the SPI-Reg-Settings during runtime I want to easyly get back to the library SPI-settings without calling the init_endat()-lib fkt again (it's unspecified what happens if i call it twice).
Could I possibly use memcopy() for that?
As suggested, this is a copy of the following question.
Why am I not provided with a default copy constructor from a volatile?
See Question&Answers more detail:os