Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1789825
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: C/C++

2015-12-09 12:05:48

intptr_t 定义在/usr/include/stdint.h,

点击(此处)折叠或打开

  1. #if __WORDSIZE == 64
  2. # ifndef __intptr_t_defined
  3. typedef long int intptr_t;
  4. # define __intptr_t_defined
  5. # endif
  6. typedef unsigned long int uintptr_t;
  7. #else
  8. # ifndef __intptr_t_defined
  9. typedef int intptr_t;
  10. # define __intptr_t_defined
  11. # endif
  12. typedef unsigned int uintptr_t;
  13. #endif

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <stdint.h>

  3. int main(void)
  4. {
  5.     int *ptr;
  6.     printf("sizeof int is %d\n",sizeof(int));
  7.     printf("sizeof char is %d\n",sizeof(char));
  8.     printf("sizeof short is %d\n",sizeof(short));
  9.     printf("sizeof long is %d\n",sizeof(long));
  10.     printf("sizeof float is %d\n",sizeof(float));
  11.     printf("sizeof double is %d\n",sizeof(double));
  12.     printf("sizeof pointer is %d\n",sizeof(ptr));
  13.     printf("sizeof unsiged int is %d\n",sizeof(unsigned int));
  14.     //store pointers in integer type,use size_t,INT_PTR,intptr_t;
  15.     printf("sizeof size_t is %d\n",sizeof(size_t));
  16.     //intptr_t defines in stdint.h
  17.     printf("sizeof intptr_t is %d\n",sizeof(intptr_t));
  18.     //INT_PTR only exist in windows
  19.     //printf("sizeof INT_PTR is %d\n",sizeof(INT_PTR));
  20.     
  21. }
查看各种数据类型的MAX 和MIN 值

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <limits.h>
  3. #include <float.h>
  4. int main()
  5. {
  6. printf("The value of INT_MAX is %i\n", INT_MAX);
  7. printf("The value of INT_MIN is %i\n", INT_MIN);
  8. printf("An int takes %d bytes\n", sizeof(int));

  9. printf("The value of FLT_MAX is %f\n", FLT_MAX);
  10. printf("The value of FLT_MIN is %.50f\n", FLT_MIN);
  11. printf("A float takes %d bytes\n", sizeof(float));

  12. printf("The value of CHAR_MAX is %d\n", CHAR_MAX);
  13. printf("The value of CHAR_MIN is %d\n", CHAR_MIN);
  14. printf("A CHAR takes %d bytes\n", sizeof(char));

  15. printf("The value of DBL_MAX is %f\n", DBL_MAX);
  16. printf("The value of DBL_MIN is %.50f\n", DBL_MIN);
  17. printf("A double takes %d bytes\n", sizeof(double));

  18. printf("The value of SHRT_MAX is %d\n", SHRT_MAX);
  19. printf("The value of SHRT_MIN is %d\n", SHRT_MIN);
  20. printf("A short takes %d bytes\n", sizeof(short));

  21. printf("The value of LONG_MAX is %Ld\n", LONG_MAX);
  22. printf("The value of LONG_MIN is %Ld\n", LONG_MIN);
  23. printf("A long takes %d bytes\n", sizeof(long));
  24. return 0;
  25. }
在stdint.h 里面定义了很多int*_t 和uint*_t 类型。

点击(此处)折叠或打开

  1. #include <apue.h>
  2. #include <stdint.h>
  3. #include <limits.h>

  4. int main(int argc, char *argv[])
  5. {
  6.     printf("CHAR_BIT is %d\n\n",CHAR_BIT);
  7.     printf("sizeof(char) is %d\n",sizeof(char));
  8.     printf("sizeof(short) is %d\n",sizeof(short));
  9.     printf("sizeof(int) is %d\n",sizeof(int));
  10.     printf("sizeof(long) is %d\n",sizeof(long));
  11.     printf("sizeof(long long) is %d\n\n",sizeof(long long));
  12.     
  13.     printf("sizeof(int8_t) is %d\n",sizeof(int8_t));
  14.     printf("sizeof(int16_t) is %d\n",sizeof(int16_t));
  15.     printf("sizeof(int32_t) is %d\n",sizeof(int32_t));
  16.     printf("sizeof(int64_t) is %d\n\n",sizeof(int64_t));

  17.     printf("sizeof(uint8_t) is %d\n",sizeof(uint8_t));
  18.     printf("sizeof(uint16_t) is %d\n",sizeof(uint16_t));
  19.     printf("sizeof(uint32_t) is %d\n",sizeof(uint32_t));
  20.     printf("sizeof(uint64_t) is %d\n",sizeof(uint64_t));
  21.     
  22.     char a,b;
  23.     printf("sizeof(a+b) is %d\n",sizeof(a+b));
  24.     }




阅读(1689) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~