【发布时间】:2010-12-14 23:36:06
【问题描述】:
在 MPLAB IDE 中,数据类型的大小是多少(int、unsigned int、float、unsigned float、char...)?
【问题讨论】:
在 MPLAB IDE 中,数据类型的大小是多少(int、unsigned int、float、unsigned float、char...)?
【问题讨论】:
如果不知道要为哪个 CPU 编译代码,这很难。假设例如Microchip 用于 PIC18 的 C18 编译器 User Guide 规定了以下基本类型大小:
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
请注意,这包括一些在 C 中不标准的类型 (short long)。
【讨论】:
int、long 等的值从未在所有编译器中进行标准定义 (reference)。因此,建议使用该库:
#include <stdint.h>
要将此库用于您自己的目的,请尝试使用以下代码:
typedef uint8_t BYTE
typedef uint16_t WORD
typedef uint32_t LONG
然后您只需使用这些来定义您的变量。此方法通常使用 integer.h 文件来存储这些定义,并包含在任何需要的地方。
【讨论】:
我会警惕这样的概括。 MPLAB 只是一个 IDE——它适用于不同的芯片。 Microchip 有 8 位控制器,如 PIC18F、16 位和 32 位控制器。每种数据类型可能不同,并对性能产生严重影响。 IE。对于 8 位芯片,16 位和 32 位数据类型可以在软件中进行模拟,这并不总是您想要的。
【讨论】:
#include<stdint.h>
long x;
这两件事帮助我度过了难关;) 和其余的信息。已被其他人共享。
【讨论】: