在 MPLAB IDE中int
,数据类型(、、、、、...)的大小是多少?unsigned int
float
unsigned float
char
问问题
26958 次
5 回答
6
如果不知道要为哪个 CPU 编译代码,这很难。假设例如 Microchip 的 PIC18 的 C18 编译器,用户指南规定了以下基本类型大小:
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
请注意,这包括一些short long
在 C 中不是标准的类型 ( )。
于 2009-11-10T10:25:43.200 回答
2
int、long 等的值从未在所有编译器(参考)中进行标准定义。因此,建议使用该库:
#include <stdint.h>
要将此库用于您自己的目的,请尝试使用如下代码:
typedef uint8_t BYTE
typedef uint16_t WORD
typedef uint32_t LONG
然后你只需使用这些来定义你的变量。此方法通常使用 integer.h 文件来存储这些定义并包含在任何需要的地方。
于 2016-01-21T12:31:24.227 回答
1
我会警惕这样的概括。MPLAB 只是一个 IDE——它适用于不同的芯片。Microchip 有 8 位控制器,如 PIC18F、16 位和 32 位控制器。每种数据类型可能不同,并对性能产生严重影响。即对于 8 位芯片,16 位和 32 位数据类型可以在软件中模拟,这并不总是您想要的。
于 2009-11-10T18:17:19.447 回答
-3
#include<stdint.h>
long x;
这两件事帮助我度过了难关;)还有其他信息。已经被其他人共享了。
于 2017-02-04T20:12:08.377 回答