C++中int,Uint,uint16等有什么区别以及用处?

spurs 2007-10-23 09:27:09
问个比较初级的问题,在C++中,既然有了int,为什么还要有uint?特别是uint16,uint32等又有什么用?他们有什么区别?基本的概念我也知道,就是不知道什么地方用这些东西?请大家最好给举个例子,谢谢!
...全文
7108 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jwsh1984 2009-02-26
  • 打赏
  • 举报
回复
我怎么在x86_64上看的, int 是 32位, long是64位的呢?
spurs 2007-10-26
  • 打赏
  • 举报
回复
谢谢各位热心的朋友!
飞哥 2007-10-23
  • 打赏
  • 举报
回复
一。表示范围
二。注意符号
yixiao386 2007-10-23
  • 打赏
  • 举报
回复
这个不用管,只是数据的存储方式而已,看需要了
xiantongyuan 2007-10-23
  • 打赏
  • 举报
回复
大小的区别,
int就是一个机器字长
uint就是一个无符号的int
uint16就是一个无符号的16位整型
uint32就是一个无符号的32位整型
spurs 2007-10-23
  • 打赏
  • 举报
回复
谢谢!
孩皮妞野 2007-10-23
  • 打赏
  • 举报
回复
int是C/C++数据类型,uint,uint16,uint32并不是C/C++内建的类型,而只是一些typedef

可能的定义如下

typedef unsinged int uint; //为了省事啊,这样不用写unsigned int而只需要写uint

typedef unsigned short uint16;// int的size取决于平台,比如16位平台上sizeof(16)为2,32为上为4,64位上为8
// 而short的size则保证为2字节,在需要明确指明数据大小时可以使用

typedef unsigned long uint32;//道理同上,sizeof(long)一定为32,看看,在64位机上sizeof(long)<sizeof(int)
看到一个不错的c++实现的md5算法 class MD5 { public: typedef unsigned int size_type; // must be 32bit MD5(); MD5(const std::string& text); void update(const unsigned char *buf, size_type length); void update(const char *buf, size_type length); MD5& finalize(); std::string hexdigest() const; friend std::ostream& operator<<(std::ostream&, MD5 md5); private: void init(); typedef unsigned char uint1; // 8bit typedef unsigned int uint4; // 32bit enum {blocksize = 64}; // VC6 won't eat a const static int here void transform(const uint1 block[blocksize]); static void decode(uint4 output[], const uint1 input[], size_type len); static void encode(uint1 output[], const uint4 input[], size_type len); bool finalized; uint1 buffer[blocksize]; // bytes that didn't fit in last 64 byte chunk uint4 count[2]; // 64bit counter for number of bits (lo, hi) uint4 state[4]; // digest so far uint1 digest[16]; // the result // low level logic operations static inline uint4 F(uint4 x, uint4 y, uint4 z); static inline uint4 G(uint4 x, uint4 y, uint4 z); static inline uint4 H(uint4 x, uint4 y, uint4 z); static inline uint4 I(uint4 x, uint4 y, uint4 z); static inline uint4 rotate_left(uint4 x, int n); static inline void FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); static inline void GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); static inline void HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); static inline void II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); }; std::string md5(const std::string &str);

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧