Discussion:
[PIC] Integer sizes
David Duffy (AVD)
2018-10-29 04:25:52 UTC
Permalink
I must be having a blonde moment.  I've inherited some C code that is
littered with "unsigned int" and "signed int" variables.  How do I find
what size they would have been in a given mplabx project?
David...

--
___________________________________________
David Duffy Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717 Fax: +61 7 38234717
Our Web Site: www.audiovisualdevices.com.au
___________________________________________

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listi
Manu Abraham
2018-10-29 04:41:55 UTC
Permalink
Hi,

"Generally", "int" has the native register width of the CPU under consideration.
However, you can also use the sizeof() keyword to find the same.

The answer to your question depends on the CPU architecture:

If you use the XC8 compiler, the datatypes are defined here:
https://ww1.microchip.com/downloads/en/DeviceDoc/52053B.pdf

If you use the XC16 compiler, the datatypes are defined here:
http://ww1.microchip.com/downloads/en/DeviceDoc/DS50002071GFinal1.pdf

If you use the XC32 compiler, the datatypes are defined here:
http://ww1.microchip.com/downloads/en/DeviceDoc/50001686J.pdf

Cheers,
Manu

On Mon, Oct 29, 2018 at 9:56 AM David Duffy (AVD)
<***@audiovisualdevices.com.au> wrote:
>
> I must be having a blonde moment. I've inherited some C code that is
> littered with "unsigned int" and "signed int" variables. How do I find
> what size they would have been in a given mplabx project?
> David...
>
> --
> ___________________________________________
> David Duffy Audio Visual Devices P/L
> Unit 8, 10 Hook St, Capalaba 4157 Australia
> Ph: +61 7 38235717 Fax: +61 7 38234717
> Our Web Site: www.audiovisualdevices.com.au
> ___________________________________________
>
> --
> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
smplx
2018-10-29 12:21:16 UTC
Permalink
On Mon, 29 Oct 2018, Manu Abraham wrote:

> Hi,
>
> "Generally", "int" has the native register width of the CPU under consideration.
> However, you can also use the sizeof() keyword to find the same.
>
> The answer to your question depends on the CPU architecture:
>
> If you use the XC8 compiler, the datatypes are defined here:
> https://ww1.microchip.com/downloads/en/DeviceDoc/52053B.pdf
>
> If you use the XC16 compiler, the datatypes are defined here:
> http://ww1.microchip.com/downloads/en/DeviceDoc/DS50002071GFinal1.pdf
>
> If you use the XC32 compiler, the datatypes are defined here:
> http://ww1.microchip.com/downloads/en/DeviceDoc/50001686J.pdf
>
> Cheers,
> Manu
>
> On Mon, Oct 29, 2018 at 9:56 AM David Duffy (AVD)
> <***@audiovisualdevices.com.au> wrote:
>>
>> I must be having a blonde moment. I've inherited some C code that is
>> littered with "unsigned int" and "signed int" variables. How do I find
>> what size they would have been in a given mplabx project?
>> David...
>>

Ah the joys of GCC...

Although I have never used gcc on the PIC I have used it a great deal in a
lot of other environments and I seem to remember getting caught once or
twice because of switches in the command line. So whatever else you do
check the actual command line used to build the "inherited" code. If
using "make" check the CFLAGS make variable.

Regards
Sergio Masci
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
David Duffy (AVD)
2018-10-29 22:32:34 UTC
Permalink
This post might be inappropriate. Click to display it.
Brent Brown
2018-10-30 01:23:14 UTC
Permalink
On 30 Oct 2018 at 8:32, David Duffy (AVD) wrote:

> I need to take a couple of steps back and see what's going on.
> Following
> the advisory about the 32-bit floating point changes, there are "no
> room
> for xxx" errors.

I cringe every time I see that "no room" message.

> The original code given to me did compile, but had little room left
> over
> for both data and program space.  Over the last couple of months I
> had
> made small changes and it has always compiled.

I have an old 16F877A project constantly nudging the flash size limt. I'm constanlty
using #define around sections of working code to drop them out so I can make
additions/changes, then optimise/tweak till everything fits again. I actually have a
fortuitously placed line in my source code which reads // asm(" NOP"); and
strangely it can sometimes make the code fit by adding it. (When really grasping for
the last few handfuls of program words I imagine it makes a difference what blocks
get located where and how the unused space does or doesn't come together,
considering page boundaries and everything).

> I was only when I moved to mplabx 5.05 and xc8 2.00 that things
> turned
> weird.  I've now installed mplabx 4.15 and xc8 1.45 but the code
> that
> used to compile now doesn't so something else is going on.

Hope you find that something else. MPLAB version I wouldn't expect to affect code
size, but I guess plug-ins like MCC could, and compliler version would for sure.

Where possible I sometimes tell the compiler I'm using a larger chip and see if it
can compile to get a feel for how much over size it is. Good luck~!


--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
David Duffy (AVD)
2018-10-30 01:29:28 UTC
Permalink
That's a great idea.  At least then I can separate the memory limit from
any other issues that may be there.
David...

On 30/10/2018 11:23 AM, Brent Brown wrote:
> Where possible I sometimes tell the compiler I'm using a larger chip and see if it
> can compile to get a feel for how much over size it is. Good luck~!

--
___________________________________________
David Duffy Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717 Fax: +61 7 38234717
Our Web Site: www.audiovisualdevices.com.au
___________________________________________

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/picl
James Cameron
2018-10-29 04:44:55 UTC
Permalink
In general, you can't, which is why we've all moved to those neat new
types.

However, in a pinch you should be able to use sizeof(unsigned int), or
sizeof(variable), to get an idea of the size in bytes. But you have
to know how big your bytes are. ;-)

On Mon, Oct 29, 2018 at 02:25:52PM +1000, David Duffy (AVD) wrote:
> I must be having a blonde moment.  I've inherited some C code that is
> littered with "unsigned int" and "signed int" variables.  How do I find
> what size they would have been in a given mplabx project?
> David...
>
> --
> ___________________________________________
> David Duffy Audio Visual Devices P/L
> Unit 8, 10 Hook St, Capalaba 4157 Australia
> Ph: +61 7 38235717 Fax: +61 7 38234717
> Our Web Site: www.audiovisualdevices.com.au
> ___________________________________________
>
> --
> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist

--
James Cameron
http://quozl.netrek.org/
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
David Duffy (AVD)
2018-10-29 05:06:44 UTC
Permalink
This project was originally compiled with XC8 version 1.xx I believe.

Space is tight and in mplabx 5.05 with xc8 2.00 I'm getting compile
errors that point to an increase in the native int size.

I'll have to check again, but the error also mentioned floating point
32-bit and 24-bit sizes.

I thought it was xc8 2.00 introducing the errors, but switching the
project to xc8 1.45 didn't help.
David...

On 29/10/2018 2:44 pm, James Cameron wrote:
> In general, you can't, which is why we've all moved to those neat new
> types.
>
> However, in a pinch you should be able to use sizeof(unsigned int), or
> sizeof(variable), to get an idea of the size in bytes. But you have
> to know how big your bytes are. ;-)
>
> On Mon, Oct 29, 2018 at 02:25:52PM +1000, David Duffy (AVD) wrote:
>> I must be having a blonde moment.  I've inherited some C code that is
>> littered with "unsigned int" and "signed int" variables.  How do I find
>> what size they would have been in a given mplabx project?
>> David...
>>
>>

--
___________________________________________
David Duffy Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717 Fax: +61 7 38234717
Our Web Site: www.audiovisualdevices.com.au
___________________________________________

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman
David Duffy (AVD)
2018-10-29 05:09:42 UTC
Permalink
The error is "Non line specific message:: advisory: (1493) updated
32-bit floating-point routines might trigger "can't find space" messages
appearing after updating to this release; consider using the smaller
24-bit floating-point types".
David...

On 29/10/2018 3:06 pm, David Duffy (AVD) wrote:
> This project was originally compiled with XC8 version 1.xx I believe.
>
> Space is tight and in mplabx 5.05 with xc8 2.00 I'm getting compile
> errors that point to an increase in the native int size.
>
> I'll have to check again, but the error also mentioned floating point
> 32-bit and 24-bit sizes.
>
> I thought it was xc8 2.00 introducing the errors, but switching the
> project to xc8 1.45 didn't help.
> David...
>
> On 29/10/2018 2:44 pm, James Cameron wrote:
>> In general, you can't, which is why we've all moved to those neat new
>> types.
>>
>> However, in a pinch you should be able to use sizeof(unsigned int), or
>> sizeof(variable), to get an idea of the size in bytes. But you have
>> to know how big your bytes are. ;-)
>>
>> On Mon, Oct 29, 2018 at 02:25:52PM +1000, David Duffy (AVD) wrote:
>>> I must be having a blonde moment.  I've inherited some C code that is
>>> littered with "unsigned int" and "signed int" variables.  How do I find
>>> what size they would have been in a given mplabx project?
>>> David...
>>>
>>>


--
___________________________________________
David Duffy Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717 Fax: +61 7 38234717
Our Web Site: www.audiovisualdevices.com.au
___________________________________________

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinf
Jan-Erik Söderholm
2018-10-29 07:13:55 UTC
Permalink
> I'm getting compile errors

No you are not. You are getting an "advisory" message.
Do you have any floating point variables and code?
If so, you might do as advised. Or not.

But you are not getting (or has at least not showed) any errors.

Jan-Erik.


-----Ursprungligt meddelande-----
Från: piclist-***@mit.edu <piclist-***@mit.edu> För David Duffy (AVD)
Skickat: den 29 oktober 2018 06:10
Till: Microcontroller discussion list - Public. <***@mit.edu>
Ämne: Re: [PIC] Integer sizes

The error is "Non line specific message:: advisory: (1493) updated 32-bit floating-point routines might trigger "can't find space" messages appearing after updating to this release; consider using the smaller 24-bit floating-point types".
David...

On 29/10/2018 3:06 pm, David Duffy (AVD) wrote:
> This project was originally compiled with XC8 version 1.xx I believe.
>
> Space is tight and in mplabx 5.05 with xc8 2.00 I'm getting compile
> errors that point to an increase in the native int size.
>
> I'll have to check again, but the error also mentioned floating point
> 32-bit and 24-bit sizes.
>
> I thought it was xc8 2.00 introducing the errors, but switching the
> project to xc8 1.45 didn't help.
> David...
>
> On 29/10/2018 2:44 pm, James Cameron wrote:
>> In general, you can't, which is why we've all moved to those neat new
>> types.
>>
>> However, in a pinch you should be able to use sizeof(unsigned int),
>> or sizeof(variable), to get an idea of the size in bytes. But you
>> have to know how big your bytes are. ;-)
>>
>> On Mon, Oct 29, 2018 at 02:25:52PM +1000, David Duffy (AVD) wrote:
>>> I must be having a blonde moment. I've inherited some C code that
>>> is littered with "unsigned int" and "signed int" variables. How do
>>> I find what size they would have been in a given mplabx project?
>>> David...
>>>
>>>


--
___________________________________________
David Duffy Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717 Fax: +61 7 38234717
Our Web Site: www.audiovisualdevices.com.au ___________________________________________

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist


--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http
Mike
2018-10-29 08:46:47 UTC
Permalink
On 29/10/2018 07:13, Jan-Erik Söderholm wrote:
>> I'm getting compile errors
> No you are not. You are getting an "advisory" message.
> Do you have any floating point variables and code?
> If so, you might do as advised. Or not.
>
> But you are not getting (or has at least not showed) any errors.
>
> Jan-Erik.
>
It's not even a warning so can be ignored if the project compiles and
links correctly.  The floating point library has been modified (perhaps
to increase speed) and has been made larger as a result, so if space was
very tight with previous versions it may not build with this version. 
IMO using floating point should be a last resort on small micros, it's
hardly ever actually needed.

Mike


--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/
AB Pearce - UKRI STFC
2018-10-29 09:39:23 UTC
Permalink
XC8 has been through a loop where the standard float was 24 bit, but was changed to 32 bit (without having 24 bit available). This created a lot of noise over increase in code and RAM usage, so the 24 bit was made available again, but I believe has to be specifically invoked. I don't know which version of XC8 this happened at, but it was a 1.xx release.

Also be aware that 2.00 has two possible modes - C90 (which is what the 1.xx compilers are) and C99. I believe the default is C99 and you have to set an explicit switch in MPLAB-X to use C90 mode.

One advantage of using C99 mode is that it understands the "uint8" style specification which explicitly shows the size.


> The error is "Non line specific message:: advisory: (1493) updated 32-bit floating-point routines
> might trigger "can't find space" messages appearing after updating to this release; consider
> using the smaller 24-bit floating-point types".
> David...

On 29/10/2018 3:06 pm, David Duffy (AVD) wrote:
> This project was originally compiled with XC8 version 1.xx I believe.
>
> Space is tight and in mplabx 5.05 with xc8 2.00 I'm getting compile
> errors that point to an increase in the native int size.
>
> I'll have to check again, but the error also mentioned floating point
> 32-bit and 24-bit sizes.
>
> I thought it was xc8 2.00 introducing the errors, but switching the
> project to xc8 1.45 didn't help.
> David...
>
> On 29/10/2018 2:44 pm, James Cameron wrote:
>> In general, you can't, which is why we've all moved to those neat new
>> types.
>>
>> However, in a pinch you should be able to use sizeof(unsigned int),
>> or sizeof(variable), to get an idea of the size in bytes. But you
>> have to know how big your bytes are. ;-)
>>
>> On Mon, Oct 29, 2018 at 02:25:52PM +1000, David Duffy (AVD) wrote:
>>> I must be having a blonde moment.  I've inherited some C code that
>>> is littered with "unsigned int" and "signed int" variables.  How do
>>> I find what size they would have been in a given mplabx project?
>>> David...
>>>
>>>


--
___________________________________________
David Duffy Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717 Fax: +61 7 38234717
Our Web Site: www.audiovisualdevices.com.au ___________________________________________

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership op
Manu Abraham
2018-10-29 08:27:00 UTC
Permalink
David,

On Mon, Oct 29, 2018 at 10:37 AM David Duffy (AVD)
<***@audiovisualdevices.com.au> wrote:
>
> This project was originally compiled with XC8 version 1.xx I believe.
>
> Space is tight and in mplabx 5.05 with xc8 2.00 I'm getting compile
> errors that point to an increase in the native int size.

When you are specific to a certain compiler version, get hold of the
relevant user guide for that compiler version.

http://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB_XC8_C_Compiler_User_Guide_for_PIC.pdf

TABLE 4-3:
INTEGER DATA TYPES
Type
Size (bits) Arithmetic Type
__bit 1 Unsigned integer
signed char 8 Signed integer
unsigned char 8 Unsigned integer
signed short 16 Signed integer
unsigned short 16 Unsigned integer
signed int 16 Signed integer
unsigned int 16 Unsigned integer
__int24 24 Signed integer
__uint24 24 Unsigned integer
signed long 32 Signed integer
unsigned long 32 Unsigned integer
signed long long 32/64 Signed integer
unsigned long long 32/64Unsigned integer

That's clear; isn't it ?

If you find the sizes to be any different, you should file a bug with microchip.
It is not supposed to be any different. Any difference is a BUG!

Cheers,
Manu
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Neil
2018-10-29 04:47:12 UTC
Permalink
Is this for xc8 or xc32?

Cheers,
-Neil.



On 10/29/2018 12:25 AM, David Duffy (AVD) wrote:
> I must be having a blonde moment. I've inherited some C code that is
> littered with "unsigned int" and "signed int" variables. How do I find
> what size they would have been in a given mplabx project?
> David...
>

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Neil
2018-10-29 04:58:38 UTC
Permalink
This is what I have for XC32:

8.4 INTEGER DATA TYPES
Integer values in the compiler are represented in 2’s complement and
vary in size from
8 to 64 bits. These values are available in compiled code via limits.h.
char, signed char 8 -128 127
unsigned char 8 0 255
short, signed short 16 -32768 32767
unsigned short 16 0 65535
int, signed int, long, signed long 32 -2^31 2^31-1
unsigned int, unsigned long 32 0 2^32-1
long long, signed long long 64 -2^63 2^63-1
unsigned long long 64 0 2^64-1

8.5 FLOATING-POINT DATA TYPES
The compiler uses the IEEE-754 floating-point format. Detail regarding the
implementation limits is available to a translation unit in float.h.
float 32
double 32
long double 64




And for XC8:

XC8 INTEGER DATA TYPES (* = default)

bit 1
signed char 8
*unsigned char 8
*signed short 16
unsigned short 16
*signed int 16
unsigned int 16
*signed short long 24
unsigned short long 24
*signed long 32
unsigned long 32
signed long long 32
unsigned long long 32




On 10/29/2018 12:47 AM, Neil wrote:
> Is this for xc8 or xc32?
>
> Cheers,
> -Neil.
>
>
>
> On 10/29/2018 12:25 AM, David Duffy (AVD) wrote:
>> I must be having a blonde moment. I've inherited some C code that is
>> littered with "unsigned int" and "signed int" variables. How do I find
>> what size they would have been in a given mplabx project?
>> David...
>>
>

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinf
Isaac M. Bavaresco
2018-10-29 05:03:12 UTC
Permalink
printf( "%u", sizeof( int ));

or

int X = sizeof( int );

Then inspect X.


Em seg, 29 de out de 2018 01:26, David Duffy (AVD) <
***@audiovisualdevices.com.au> escreveu:

> I must be having a blonde moment. I've inherited some C code that is
> littered with "unsigned int" and "signed int" variables. How do I find
> what size they would have been in a given mplabx project?
> David...
>
> --
> ___________________________________________
> David Duffy Audio Visual Devices P/L
> Unit 8, 10 Hook St, Capalaba 4157 Australia
> Ph: +61 7 38235717 Fax: +61 7 38234717
> Our Web Site: www.audiovisualdevices.com.au
> ___________________________________________
>
> --
> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
>
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Loading...