In MPLAB IDE what is the sizes of data types (int
, unsigned int
, float
, unsigned float
, char
...)?
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.
Here is the implementation of integer data types on different MPLAB XC compilers.
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.
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.
#include<stdint.h>
long x;
These two things helped me get through ;) And the rest info. is already shared by other folks.
© 2022 - 2024 — McMap. All rights reserved.