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

CCS equivalent or correct declaration

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



Joined: 05 Nov 2008
Posts: 18

View user's profile Send private message

CCS equivalent or correct declaration
PostPosted: Fri May 25, 2012 4:40 am     Reply with quote

Hi I am attempting to port some code that has been given to me in Hitech C format and I am unfamiliar with structures and unions, as I am a newbie.

I have fixed the structures by redefining the data types to the correct CCS ones.
But the union is giving me a headache.

************************************
Code:
                   
#define bool  unsigned char
#define u8    unsigned char
#define s8    signed   char
#define u16   unsigned int16
#define s16   signed   int16               
#define u32   unsigned int32   
#define s32   signed   int32
                                                           

#define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))

//------------------------
typedef struct     
{
   u8   L;
   u8   H;
} HL8;
                               
typedef union
{
   u16 _U16;     
   HL8 _U8;               
}HL16;

typedef struct
{
   u16   L;
   u16   H;
}HL32;

typedef struct
{
   s16   L;
   s16   H;
}HLS32;

// fixed point union 16.16               
union {
   HLS32  S16;  //[Error] Expecting an identifier, Expecting a declaration.
   HL32   U16;                               
   u8     U8[4];           
   u32    U32;     
   s32    S32;
} fp32;


***********************************************************

Thanks in advance.
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Fri May 25, 2012 7:06 am     Reply with quote

Problem is re-use of names. Unless you have turned on #case, you already have s16 defined, which is the same as S16.....

Personally, even if you turn case on, I'd avoid re-using names that are the same except for a case change.

Best Wsihes
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