I'm trying to write a C++ program for an Atmel Microcontroller.
I need to use some of the functions that were already written in the ASF library, and I'm doing this by copying some of the code into C++ functions.
I get this error on compilation:
'union Pm' has no member named 'PM_CPUMASK'
The Pm
type union looks something like this:
typedef union {
struct {
....
} bf;
struct {
....
RwReg PM_CPUMASK;
....
} reg;
} Pm;`
In the ASF code, the member PM_CPUMASK
is accessed like this:
unsigned int mask = *(&PM->PM_CPUMASK + busId);
But I get an error. I think this is valid in C, but in C++ I would need to access the named struct and then the actual member. Using *(&PM->reg.PM_CPUMASK...)
I get no error, but is there a way to activate this style of member accessing in C++ compiler?
BTW, there's no naming conflicts in the members of the 2 structs. Thanks.
I would guess that you copy-pasted the code and then modified it. The original code was something like this
typedef union {
struct {
....
};
struct {
....
RwReg PM_CPUMASK;
....
};
} Pm;
What is anonymous struct, that is a compiler extension, and there is no default extensions like this for C++ compiler, see here.
And then you added names to those structs. That is why you have to use another identifier to access the member.
Sorry if my guessing is wrong. But the point is that you have to use an additional name there.