zoukankan      html  css  js  c++  java
  • C++ x86程序与x64程序中,各种内置类型的大小比较

    代码:

    #include <iostream>
    #include <cstdio>
    #include <list>
    #include <string>
    #include <cstdint>
    #include <exception>
    
    #define PRINT_SIZE(type) printf("%-17s = %zu,inner type: %s
    ", "sizeof("#type")", sizeof(type), typeid(type).name())
    
    void print_sys_bits()
    {
    #ifdef _WIN64
        std::cout << "x64:" << std::endl;
    #else
        std::cout << "x86:" << std::endl;
    #endif
    }
    
    void print_sizes()
    {
        PRINT_SIZE(void*);
        PRINT_SIZE(float);
        PRINT_SIZE(double);
        PRINT_SIZE(short);
        PRINT_SIZE(int);
        PRINT_SIZE(long);
        PRINT_SIZE(long long);
        PRINT_SIZE(int8_t);
        PRINT_SIZE(uint8_t);
        PRINT_SIZE(int16_t);
        PRINT_SIZE(uint16_t);
        PRINT_SIZE(int32_t);
        PRINT_SIZE(uint32_t);
        PRINT_SIZE(int64_t);
        PRINT_SIZE(uint64_t);
    }
    
    int32_t main()
    {
        print_sys_bits();
        print_sizes();
        std::cin.get();
        return 0;
    }

    在不同的开发环境中,分别编译出x86程序和x64程序,观察执行结果

    环境: Win10_64位 + VS2015_32位

    在上面的结果中,除了指针的size不一样之外,其它的内置类型是完全相同的.

  • 相关阅读:
    易语言常用源码
    ci的数据库地址
    格式化输出php数组
    mysql插入表情问题
    线程、进程与协程2
    线程、进程与协程
    if __name=='__main__"的作用
    动态导入模块
    面向对象补充之方法
    getpass模块
  • 原文地址:https://www.cnblogs.com/tangxin-blog/p/8290540.html
Copyright © 2011-2022 走看看