【问题标题】:MPLAB IDE data type sizesMPLAB IDE 数据类型大小
【发布时间】:2010-12-14 23:36:06
【问题描述】:

在 MPLAB IDE 中,数据类型的大小是多少(intunsigned intfloatunsigned floatchar...)?

【问题讨论】:

    标签: c size mplab size-type


    【解决方案1】:

    如果不知道要为哪个 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)。

    【讨论】:

    • 我能否建议您声明这些值适用于 Microchip 的 PIC18 系列 C18 编译器?我知道链接的用户指南提供了该信息,但是将其包含在此处也会使此答案更加完整。此外,鉴于问题没有指定编译器和目标微控制器,因此应该强调其他目标的类型可能不同。
    【解决方案2】:

    int、long 等的值从未在所有编译器中进行标准定义 (reference)。因此,建议使用该库:

    #include <stdint.h>
    

    要将此库用于您自己的目的,请尝试使用以下代码:

    typedef uint8_t    BYTE
    typedef uint16_t   WORD
    typedef uint32_t   LONG
    

    然后您只需使用这些来定义您的变量。此方法通常使用 integer.h 文件来存储这些定义,并包含在任何需要的地方。

    【讨论】:

      【解决方案3】:

      这是整数数据类型在不同 MPLAB XC 编译器上的实现。

      1. 8 位设备的数据类型(在 XC8 编译器上实现):

      2. 16 位设备的数据类型(在 XC16 编译器上实现):

      3. 32 位设备的数据类型(在 XC32 编译器上实现):

      【讨论】:

        【解决方案4】:

        我会警惕这样的概括。 MPLAB 只是一个 IDE——它适用于不同的芯片。 Microchip 有 8 位控制器,如 PIC18F、16 位和 32 位控制器。每种数据类型可能不同,并对性能产生严重影响。 IE。对于 8 位芯片,16 位和 32 位数据类型可以在软件中进行模拟,这并不总是您想要的。

        【讨论】:

          【解决方案5】:
          #include<stdint.h>
          long x;
          

          这两件事帮助我度过了难关;) 和其余的信息。已被其他人共享。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2011-03-14
            • 2015-08-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-11-07
            相关资源
            最近更新 更多