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

byte alignment on struct (PCD)
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Thu May 31, 2012 4:28 pm     Reply with quote

Mia culpa. I meant 4.120.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu May 31, 2012 11:46 pm     Reply with quote

Quote:
I meant 4.120

Makes sense.

The compiler result in your previous post with incorrect treatment of x.b = y.b can be found for a range of PCD versions,
at least V4.107 to 4.127. Versions up to 4.099 and from 4.128 show the below compilation result, which uses
a fill byte and allocates the struct to an even address.

Code:
.................... x = y; 
079A:  PUSH    80C
079C:  POP     808
079E:  PUSH    80E
07A0:  POP     80A
.................... x.a = y.a; 
07A2:  MOV.B   80C,W0L
07A4:  MOV.B   W0L,808
.................... x.b = y.b; 
07A6:  PUSH    80E
07A8:  POP     80A
.................... x.b.high = y.b.high; 
07AA:  MOV.B   80E,W0L
07AC:  MOV.B   W0L,80A
.................... x.b.low = y.b.low; 
07AE:  MOV.B   80F,W0L
07B0:  MOV.B   W0L,80B
.................... x.b = 513;
07B2:  MOV     #201,W4
07B4:  MOV     W4,80A


The shown bug in V4.120 et al isn't unique, there are also other issues, e.g. with bit fields crossing a byte boundary
that have been recently fixed. PCD is approaching a final state.

Unfortunately you have to test-compile your code with a number of versions to indentify the bug fix. CCS doesn't like an
exact change history, may be they fear to confuse users with detail information?

As a side remark not related to the problem. Your structure definition seems to expect Big-Endian data format, but
PIC uses Little-Endian.

To get the expected result from x.b = 513
Code:
   struct
   {
      uint8 high;
      uint8 low;
   };

should be changed to
Code:
   struct
   {
      uint8 low;
      uint8 high;
   };
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Sat Jun 02, 2012 6:00 am     Reply with quote

I understand now. Thanks for the hints FvM.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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