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 support@ccsinfo.com

Bit Field Error in Data Structure

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



Joined: 23 Jan 2018
Posts: 44

View user's profile Send private message

Bit Field Error in Data Structure
PostPosted: Thu Mar 30, 2023 5:30 am     Reply with quote

Hi,
I am using PIC18F66K40 in one of my project to communicate with a peripheral
device and for register mapping of the peripheral I am using data structure with bit field.
Code:

typedef struct _ST_REG_0x01
{
    unsigned int8 ADC_MODE : 2;
    unsigned int8 CS_SEL   : 2;
    unsigned int8 CLK_SEL  : 2;
    unsigned int8 CONFIG0  : 2;
}ST_REG_0x01;
typedef union _UN_CONFIG0_REG_01h
{
    ST_REG_0x01     m_ST_REG_0x01_bits;
    unsigned int8   m_ui8Reg_0x1;
   
}UN_CONFIG0_REG_01h_t;



typedef struct _ST_REG_0x02
{
    unsigned int8 Reserved  : 2;
    unsigned int8 OSR       : 4;
    unsigned int8 PRESCALER : 2;
}ST_REG_0x02;
typedef union _UN_CONFIG1_REG_02h
{
    ST_REG_0x02     m_ST_REG_0x02_bits;
    unsigned int8   m_ui8Reg_0x2;
   
}UN_CONFIG1_REG_02h_t;

The first register data structure does not generate any error whereas the second one generates errors like :
Error#28 Expecting an identifier
Error#36 Expecting a ; or ,
Error#34 Unknown type

My compiler version is 5.101
I can't find out any possible wayout from the errors.
Anyone with any idea about that will be helpful.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Thu Mar 30, 2023 6:29 am     Reply with quote

As posted, both compile without errors for me, on your compiler version.
I'd suggest that possibly you have something else possibly defined, that
is causing the issue. So perhaps 'Reserved' is #defined somewhere, or
'PRESCALER'. The latter in particular might well be #defined in one of
the standard libraries.

If you are in the standard IDE, and this is happening, the item that is
causing this should be underlined in red when the compile fails.
Mrinmoy Dey



Joined: 23 Jan 2018
Posts: 44

View user's profile Send private message

PostPosted: Thu Mar 30, 2023 11:10 am     Reply with quote

@Ttelmah
You are absolutely right; the Reserved member variable in the data structure was the problem and that may be #defined somewhere in the standard library with the exactly same spelling. Once I make it in caps the code is successfully compiled.

Thank you so much. Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Mar 31, 2023 1:54 am     Reply with quote

Glad I got it.

Also shows though how to debug such a problem. I made a bare program
and tried your structures, which then worked. Gave an instant hint to what
was happening, so I then added a #define for 'Reserved', and immediately
the problem appeared. Very Happy
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