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.

Compiler/TMS320F28379D: struct = struct, = is undefined when compiling at c++

Part Number: TMS320F28379D

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++.

  • Are you sure that in C you are not defining it as:
    struct SPI_REGS *test?

    AFAIK, C cannot do a structure copy, but it can do a pointer copy.
  • Yes I'm sure.

    I used the EnDat2.2 example and tested some things.

    And in the PM_endat22-Main.c

    i have the following code:

    global:
    struct SPI_REGS SPI_REGS_4_ABSOLUT;

    and later in the main():
    SPI_REGS_4_ABSOLUT = SpibRegs;

    and it works totally fine.
  • 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.)

  • Does the definition of struct SPI_REGS involve a union?
  • 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.