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

Struct number of bits out of range error

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



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

Struct number of bits out of range error
PostPosted: Mon Feb 28, 2011 1:18 pm     Reply with quote

Hello
Can someone tell me why this?
If I define the struct with element 2 as 4 bits it compiles without an issue.

Code:

struct wwvbtime {    //top 32 bits received
   int   nu1;        //top 8 bits of 32 not used
   int   nu2   :4;   //next 7 bits of 32 not used
   int   mt    :3;   //tens of minutes
   int   nu3   :1;   //one bit not used
   int   m     :4;   //minutes
   int   nu4   :2;   //two bits not used
   int   ht    :2;   //tens of hours
   int   nu5   :1;   //one bit not used
   int   h     :4;   //hours
} rxhigh;


But if I replace the 4 bits with 7 bits I get a compiler error.
"Number of bits is out of range"
With 7 bits in element 2 would make the total bits in the struct = 32.

Code:

struct wwvbtime {    //top 32 bits received
   int   nu1;        //top 8 bits of 32 not used
   int   nu2   :7;   //next 7 bits of 32 not used
   int   mt    :3;   //tens of minutes
   int   nu3   :1;   //one bit not used
   int   m     :4;   //minutes
   int   nu4   :2;   //two bits not used
   int   ht    :2;   //tens of hours
   int   nu5   :1;   //one bit not used
   int   h     :4;   //hours
} rxhigh;


Compiler 4.119 PIC18F4550
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 2:38 pm     Reply with quote

You may have to email CCS for a clarification on this.

Previous threads on this topic:
Quote:
Number of bits is out of range

http://www.ccsinfo.com/forum/viewtopic.php?p=91585
http://www.ccsinfo.com/forum/viewtopic.php?p=71262
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 4:32 pm     Reply with quote

Yes, the compiler is expecting the bit fields to be aligned to byte boundaries.
Tom-H-PIC



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

What about the 3 LSBs?
PostPosted: Mon Feb 28, 2011 5:14 pm     Reply with quote

Ok is that from top (MSB) to bottom (LSB)?
I assume that is true MSB top to LSB bottom what does it do with the 3 LSB that are not declared?
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