首页 > 其他分享 >long数据类型跨平台问题

long数据类型跨平台问题

时间:2024-03-23 22:33:34浏览次数:21  
标签:typedef int 数据类型 unsigned long 跨平台 uint using

源代码

#include <iostream>

int main()
{
	std::cout << "size of long : " << sizeof(long) << std::endl;
	return 0;
}

Windows

long -> 32位

image

Linux

long -> 64位

image

建议

跨平台程序尽量采用跨平台库,如Boost

namespace boost
{

  using ::int8_t;
  using ::int_least8_t;
  using ::int_fast8_t;
  using ::uint8_t;
  using ::uint_least8_t;
  using ::uint_fast8_t;

  using ::int16_t;
  using ::int_least16_t;
  using ::int_fast16_t;
  using ::uint16_t;
  using ::uint_least16_t;
  using ::uint_fast16_t;

  using ::int32_t;
  using ::int_least32_t;
  using ::int_fast32_t;
  using ::uint32_t;
  using ::uint_least32_t;
  using ::uint_fast32_t;

# ifndef BOOST_NO_INT64_T

  using ::int64_t;
  using ::int_least64_t;
  using ::int_fast64_t;
  using ::uint64_t;
  using ::uint_least64_t;
  using ::uint_fast64_t;

# endif

  using ::intmax_t;
  using ::uintmax_t;

}

或者stdint.h

typedef signed char        int8_t;
typedef short              int16_t;
typedef int                int32_t;
typedef long long          int64_t;
typedef unsigned char      uint8_t;
typedef unsigned short     uint16_t;
typedef unsigned int       uint32_t;
typedef unsigned long long uint64_t;

typedef signed char        int_least8_t;
typedef short              int_least16_t;
typedef int                int_least32_t;
typedef long long          int_least64_t;
typedef unsigned char      uint_least8_t;
typedef unsigned short     uint_least16_t;
typedef unsigned int       uint_least32_t;
typedef unsigned long long uint_least64_t;

typedef signed char        int_fast8_t;
typedef int                int_fast16_t;
typedef int                int_fast32_t;
typedef long long          int_fast64_t;
typedef unsigned char      uint_fast8_t;
typedef unsigned int       uint_fast16_t;
typedef unsigned int       uint_fast32_t;
typedef unsigned long long uint_fast64_t;

typedef long long          intmax_t;
typedef unsigned long long uintmax_t;

标签:typedef,int,数据类型,unsigned,long,跨平台,uint,using
From: https://www.cnblogs.com/hywing/p/18091827

相关文章

  • mysql中的数据类型大全纯干货------------时间日期类型
    简介(类型预览):在mysql8.0版本中支持的类型主要有:YEAR类型表示年DATE类型表示年,月,日TIME类型表示时,分,秒DATETIME类型表示年,月,日,时,分,秒TIMESTAMP类型通常表示带时区的年,月,日,时,分,秒数据类型单位占用字节格式下限上限YEAR年1YYY或YY19012155TIME时间3H......
  • 1.变量与数据类型、输出与输入
    C语言语法知识点1.变量与数据类型、输出与输入C中每个变量都有特定的类型,类型决定了变量存储的大小。变量的名称可以由字母、数字和下划线字符组成。它必须以字母或下划线开头。有以下几种基本的变量类型:类型char字符型,1字节(1字节8位,即1字节=8bit)int整型,4字节......
  • 数据类型
    一、常用数据类型整数类型:INT(或INTEGER)定点数类型:DECIMAL日期时间类型:YEAR、TIME、DATE、DATETIME、TIMESTAMP文本字符串类型:CHAR、VARCHAR、TEXT二、整数类型例子:--1、建表createtabledemo.demo1(numint);--2、插入数据insertintodemo.demo1values(null)......
  • Qt/C++通用跨平台Onvif工具/支持海康大华宇视华为天地伟业等/云台控制/预置位管理/工
    一、前言在安防视频监控行业,Onvif作为国际标准,几乎主要的厂商都支持,不仅包含了国内的厂商,也包括主要的国际厂商,由于有了这个标准的存在,使得不同设备不同安防平台之间,能够接入各个厂家的硬件设备,互通有无,你中有我我中有你,实现良性竞争。ONVIF是一个全球性的开放式行业协议,其目标是......
  • 6.Go语言基本数据类型
    Go语言基本数据类型1、Golang数据类型介绍Go语言中数据类型分为:基本数据类型和复合数据类型基本数据类型有:整型、浮点型、布尔型、字符串复合数据类型有:数组、切片、结构体、函数、map、通道(channel)、接口等。2、整型整型分为以下两个大类:有符号整形按长度分为:int8、i......
  • 7.GoLang中基本数据类型之间的转换
    GoLang中基本数据类型之间的转换1、关于golang中的数据类型转换Go语言中只有强制类型转换,没有隐式类型转换。2、数值类型之间的相互转换数值类型包括:整形和浮点型packagemainimport"fmt"funcmain(){varaint8=20varbint16=40varc=int16......
  • C# 03 数据类型及转换
    类型:integer(int)、double、long:数値型string:文字型boolean:布尔型写法:inti=int.Parse("1234");longl=long.Parse("1234");doubled=double.Parse("124.3");boolb=bool.Parse("True");stringstr=i.ToString(); 时间Da......
  • C语言中,四则运算导致数据类型的转换
    在C语言中,四则运算可能导致数据类型的转换,这种转换称为隐式类型转换。以下是一些常见的数据类型转换情况:1.整数提升:当不同大小的整数类型(如`char`、`short`、`int`、`long`)进行混合运算时,较小的操作数会被提升为较大的类型,以便进行运算。例如,`char`类型的操作数会被提升为`......
  • 前端基础 - 数据类型篇(高频面试!!!)
    数据类型在JavaScript中,数据类型可以分为两类:基础数据类型、引用/复杂数据类型1.基础类型:String->表示文本类型,如"HelloWorld!"Number->表示数字,可以是整数或者浮点数,例如3或者3.141592,在JavaScript中,所有数字都是浮点数类型,即使没有小数部分Boolean->表示......
  • JAVA对象、类和基本数据类型
    变量和标识符数学名词:变数或变量,是指没有固定的值,可以改变的数。变量以非数字的符号来表示,一般用拉丁字母。变量和常数是相反的。变量的用处在于能一般化描述指令的方式计算机解释:变量就是系统为程序分配的一块内存单元,用来储存各种类型的数据。根据所储存的数据类型不同,有......