View previous topic :: View next topic |
Author |
Message |
bennyboos
Joined: 17 Nov 2005 Posts: 30 Location: Chester UK
|
int24 misbehaviour |
Posted: Mon Mar 13, 2006 10:45 am |
|
|
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
|
|
Posted: Mon Mar 13, 2006 11:03 am |
|
|
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
|
|
Posted: Mon Mar 13, 2006 11:05 am |
|
|
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. |
|
|
|