MPLAB IDE data type sizes
Asked Answered
O

5

1

In MPLAB IDE what is the sizes of data types (int, unsigned int, float, unsigned float, char...)?

Odont answered 10/11, 2009 at 10:21 Comment(0)
A
8

This is hard without knowing for which CPU you want to compile code. Assuming e.g. Microchip's C18 compiler for the PIC18, the User Guide states the following fundamental type sizes:

TYPE                SIZE     RANGE
char(1,2)            8 bits  -128 127
signed char          8 bits  -128 127
unsigned char        8 bits  0 255
int                 16 bits  -32,768 32,767
unsigned int        16 bits  0 65,535
short               16 bits  -32,768 32,767
unsigned short      16 bits  0 65,535
short long          24 bits  -8,388,608 8,388,607
unsigned short long 24 bits  0 16,777,215
long                32 bits  -2,147,483,648 2,147,483,647
unsigned long       32 bits  0 4,294,967,295

Note that this includes some types (short long) that are not standard in C.

Attune answered 10/11, 2009 at 10:25 Comment(1)
Can I suggest that you state that these values are for Microchip's C18 compiler for the PIC18 family? I know the linked user guide provides that information, but it would make this answer more complete to include it here as well. Also, given that the question doesn't specify a compiler and target microcontroller, it should be stressed that the types may be different sizes for other targets.Supralapsarian
N
3

Here is the implementation of integer data types on different MPLAB XC compilers.

  1. Data Types for 8-bit devices (implementation on XC8 compiler): enter image description here

  2. Data Types for 16-bit devices (implementation on XC16 compiler): enter image description here

  3. Data Types for 32-bit devices (implementation on XC32 compiler):enter image description here

Nolannolana answered 23/11, 2017 at 6:18 Comment(0)
B
2

Values for int, long, etc., are never standardly defined across all compilers(reference) . For this reason, it is advised to make use of the library:

#include <stdint.h>

To make use of this library for your own purposes, try using the code as follows:

typedef uint8_t    BYTE
typedef uint16_t   WORD
typedef uint32_t   LONG

Then you just use these to define your variables. This method usually makes use of an integer.h file to store these definitions and is included wherever needed.

Bloody answered 21/1, 2016 at 12:31 Comment(0)
E
1

I would be wary of such generalizations. MPLAB is just an IDE - it is suitable for different chips. Microchip has 8-bit controllers like PIC18F, 16-bit and 32-bit controllers. The data types for each may be different and hold serious implications for performance. I.e. for the 8-bit chips the 16 and 32 bit data types may be emulated in software, which isn't always what you want.

Edrei answered 10/11, 2009 at 18:17 Comment(0)
P
-3
#include<stdint.h>
long x;

These two things helped me get through ;) And the rest info. is already shared by other folks.

Prehensible answered 4/2, 2017 at 20:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.