CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Multiple unamed structures in a union

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
EM1SSNuke



Joined: 20 Jul 2005
Posts: 1

View user's profile Send private message

Multiple unamed structures in a union
PostPosted: Wed Jul 20, 2005 10:59 pm     Reply with quote

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







PostPosted: Thu Jul 21, 2005 3:21 am     Reply with quote

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







PostPosted: Thu Jul 21, 2005 9:33 am     Reply with quote

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








PostPosted: Thu Jul 21, 2005 9:55 am     Reply with quote

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








PostPosted: Thu Jul 21, 2005 10:10 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Jul 21, 2005 10:56 am     Reply with quote

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







PostPosted: Thu Jul 21, 2005 3:41 pm     Reply with quote

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








PostPosted: Thu Jul 21, 2005 6:24 pm     Reply with quote

Quote:

Sorry, but no.



And another source
http://www.cepba.upc.es/docs/sgi_doc/SGI_Developer/books/CLanguageRef/sgi_html/ch07.html

You need to go back and reread the document i cited it is a change to ANSI C. And i quote "After being reviewed and voted on by the member bodies such as ANSI and BSI, both documents have been formally accepted: the C standard has changed ! " The link again:
http://www.lysator.liu.se/c/tc1.html#DR017Q17-a

And i quote:
"Unnamed struct or union members are ignored during initialization."
QED. Unnamed elements are allowed.

Good Day
LomasS
Guest







PostPosted: Fri Jul 22, 2005 6:33 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 22, 2005 6:57 am     Reply with quote

Sure would be nice if they did though.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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