This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI C/C++ Compiler
I want to copy the current SpibRegs settings into a variable to use those settings again later.
The following code works fine if it is written inside a .c file
#include "F28x_Project.h"
struct SPI_REGS test;
void testing(){
test = SpibRegs;
}
but if I put it inside a .cpp file the compiler tells me the = operator is undefined for that operation.
I don't understand why this works in c but not in c++.
Well, well, well. According to Harbison and Steele:
"...and newer compilers now allow structures to be assigned, passed as parameters to functions and returned from functions. (With older compilers, assignment must be done component by component..."
5.6.2 Operations on Structures
(I don't know about C++, but Mr Google probably does.)
Yes it does.
But I think the problem is, that the SpibReg is declared volatile inside the F2837xD_GlobalVariableDefs.c.
In another little test using the GNU Compiler with -std C++98
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;
I get the followeing error:
error: binding reference of type 'const FOO&' to 'volatile FOO' discards qualifiers
A good explanation why this works in C but not in C++ can be found at:
https://stackoverflow.com/questions/17217300/why-am-i-not-provided-with-a-default-copy-constructor-from-a-volatile
Before I start writing a suitable copy-construction inside the struct I would rather use a simple memcpy(), as a little dirty workarround.