|
|
View previous topic :: View next topic |
Author |
Message |
EM1SSNuke
Joined: 20 Jul 2005 Posts: 1
|
Multiple unamed structures in a union |
Posted: Wed Jul 20, 2005 10:59 pm |
|
|
Does the CCS C compiler support multiple unnamed structures in unions?
Code: |
extern volatile union {
struct {
unsigned RB0:1;
unsigned RB1:1;
unsigned RB2:1;
unsigned RB3:1;
unsigned RB4:1;
unsigned RB5:1;
unsigned RB6:1;
unsigned RB7:1;
};
struct {
unsigned PB_INT0:1;
unsigned PB_INT1:1;
unsigned PB_INT2:1;
};
struct {
unsigned rsrv:5;
unsigned PGM:1;
unsigned PGC:1;
unsigned PGD:1;
};
} PORTBbits;
|
I keep getting the follwoing error:
*** Error 56 "C:\MCHPFSUSB\fw\Cdc\user\user.c" Line 91(18,19): Element is not a member
user.c fragment as follows:
Code: |
#define sw2 PORTBbits.RB4
#define sw3 PORTBbits.RB5
...
byte old_sw2,old_sw3;
...
old_sw2 = sw2; <----offending lines below
old_sw3 = sw3;
|
When i name the structures in the union i have no problem, e.g. b,i,p. And add then name to sw2 and sw3 the code will compile.
Thanks in advance |
|
|
Ttelmah Guest
|
|
Posted: Thu Jul 21, 2005 3:21 am |
|
|
No.
What you are trying to do, is not even legitimate C.
Without a 'name', how can the compiler tell which of the structures you actually want to use?. Though you could argue, that it can work this out from the reference used, this is not either standard, or supported in C.
The reference in C, to a component of a structure, in a union, is:
[union name].[structure name].[component]
Best Wishes |
|
|
Ttelmah Guest
|
|
Posted: Thu Jul 21, 2005 9:33 am |
|
|
It is a standard feature of _C++_, which has been reverse adopted in some C's. However even Ansi-C, does not require this, allowing the name to be dropped 'in use', if there are multiple structures containing the same named element at the same location, but still requiring it in the declarations.
Best Wishes |
|
|
Guest
|
|
Posted: Thu Jul 21, 2005 9:55 am |
|
|
Ttelmah wrote: | No.
What you are trying to do, is not even legitimate C.
|
I taught ANSI for Embedded Systems for a few years. It is part of the ANSI standard and is compiler implementation specific, per the standard.
Thanks for your time. |
|
|
Guest
|
|
Posted: Thu Jul 21, 2005 10:10 am |
|
|
Anonymous wrote: | Ttelmah wrote: | No.
What you are trying to do, is not even legitimate C.
|
I taught ANSI for Embedded Systems for a few years. It is part of the ANSI standard and is compiler implementation specific, per the standard.
Thanks for your time. |
And the proof is ....
http://www.lysator.liu.se/c/tc1.html search for 'unnamed' in the docuement. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Jul 21, 2005 10:56 am |
|
|
Ttelmah wrote: | It is a standard feature of _C++_, which has been reverse adopted in some C's. However even Ansi-C, does not require this, allowing the name to be dropped 'in use', if there are multiple structures containing the same named element at the same location, but still requiring it in the declarations.
Best Wishes |
Microsoft Specific
A Microsoft C extension allows you to declare a structure variable within another structure without giving it a name. These nested structures are called anonymous structures. C++ does not allow anonymous structures.
You can access the members of an anonymous structure as if they were members in the containing structure. |
|
|
Ttelmah Guest
|
|
Posted: Thu Jul 21, 2005 3:41 pm |
|
|
Anonymous wrote: | Anonymous wrote: | Ttelmah wrote: | No.
What you are trying to do, is not even legitimate C.
|
I taught ANSI for Embedded Systems for a few years. It is part of the ANSI standard and is compiler implementation specific, per the standard.
Thanks for your time. |
And the proof is ....
http://www.lysator.liu.se/c/tc1.html search for 'unnamed' in the docuement. |
Sorry, but no.
what you are pointing to there, is a 'coda' to the Ansi defintitions. Ansi allows anonymous members, but there is a latter coda that requires _one_ to be declared as named (this is because of the initialisation problems that are being referred to in that coda....). The current Ansi printout, specifically excludes unions with only anonymous members, though most compilers will accept this.
This was never normal C, in any form, and CCS C, is _C_, not Ansi-C (a fact that seems to often be overlooked).
Best Wishes |
|
|
Guest
|
|
|
LomasS Guest
|
|
Posted: Fri Jul 22, 2005 6:33 am |
|
|
errr.... excuse me guys, but it doesn't really matter if it's ANSI, C++, Microsoft specific or whatever.
What really matters is whether CCS allow it & it would appear that the answer is a simple No!
Now boys & [spam], let's stop arguing. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jul 22, 2005 6:57 am |
|
|
Sure would be nice if they did though. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|