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

int24 misbehaviour

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



Joined: 17 Nov 2005
Posts: 30
Location: Chester UK

View user's profile Send private message

int24 misbehaviour
PostPosted: Mon Mar 13, 2006 10:45 am     Reply with quote

In order to save space I have created a new type called int24.
Code:
typedef struct {int l; int m; int u;} int24;   // Create a new type called int24

As the name implies it is meant to be a 24bit wide integer. The only problem I have found is that it doesn't behave as one in mathematical operations.

i.e. the following postincrement misbehaves
Code:
int24 address;
address = 0x000CFF;
address++;


Instead of the resultant address being 0x000D00 the post increment only works on the LSB of my int24 yielding 0x000C00.

In a way I am not surprised by this since I haven't specified any mathmatical methods for this data type to the compiler. But only because I don't know how? If anyone knows a way can they please pass it on!
(On a separate note I prefer to use MPLAB rather than PCW - does anyone know how to customise it such that user defined types show up in bold.
i.e. long appears as bold, but int16 appears as normal text).

Thanks

Ben
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 13, 2006 11:03 am     Reply with quote

Just because you call a structure "int24" doesn't mean it is an int24.
The compiler doesn't know that you want the structure to be treated
as a integer data type. It's just another structure to the compiler.
My advice is to use int32.

-------
To enable customized color syntax in MPLAB:

1. On my system, I have a file called "userfile.txt" in this path:
Quote:
C:\Program Files\MPLAB IDE\Colors\userfile.txt

The file contains:
Quote:

int1
int8
int16
int32

I forget if the Colors directory was already there or if I created it.
But just go ahead and create the same path and the text file as
listed above.

2. In MPLAB, go to the Edit menu / Properties / Text tab.

3. Down at the bottom of the window, type in the full pathname as
given above.

4. Then click on the "Choose Colors" button in that same window.

5. A list of data types and other items will be displayed. Down at
the bottom, click on "User File Defined". Then click on the
boxes for "Foreground Color" and "Background Color" and set them
to your desired colors. Click OK and then Apply, and that should
do it.
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

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

PostPosted: Mon Mar 13, 2006 11:05 am     Reply with quote

This isn't C++, you can't override operators (like ++ and =, which you are using) to perform operations on custom datatypes. You will have to write your own routines to handle these operations on custom datatypes.
_________________
I came, I saw, I compiled.
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