c语言在发展的历程中经历了c89和c99两个标准,为了实现c语言的跨平台的优点,就是在windows和Linux以及Unix上都可以执行,就需要进行一些跨平台的技巧了,但是不但c语言的标准多种多样,并且c语言的编译器也有很多种,gcc,lcc,vc++等,比如:对于int型有的编译器赋予4个字节,有的赋予2个字节。再次我给大家介绍一个好的技巧,就是inttypes.h头文件,这个头文件一般在编译器里边都有,#include<inttypes.h>以后就可以直接根据字节数目来定义变量而不是通过其他的.

以下是这个头文件在gcc编译器的代码,其他的类似

  1. bash-3.00$ vi int_types.h
  2. "int_types.h" [Read only] 176 lines, 4367 characters
  3. /*
  4. * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  5. * Use is subject to license terms.
  6. */
  7. #ifndef _SYS_INT_TYPES_H
  8. #define _SYS_INT_TYPES_H
  9. #pragma ident   "@(#)int_types.h        1.10    04/09/28 SMI"
  10. /*
  11. * This file, <sys/int_types.h>, is part of the Sun Microsystems implementation
  12. * of <inttypes.h> defined in the ISO C standard, ISO/IEC 9899:1999
  13. * Programming language - C.
  14. *
  15. * Programs/Modules should not directly include this file.  Access to the
  16. * types defined in this file should be through the inclusion of one of the
  17. * following files:
  18. *
  19. *      <sys/types.h>           Provides only the "_t" types defined in this
  20. *                              file which is a subset of the contents of
  21. *                              <inttypes.h>.  (This can be appropriate for
  22. *                              all programs/modules except those claiming
  23. *                              ANSI-C conformance.)
  24. *
  25. *      <sys/inttypes.h>        Provides the Kernel and Driver appropriate
  26. *                              components of <inttypes.h>.
  27. *
  28. *      <inttypes.h>            For use by applications.
  29. *
  30. * See these files for more details.
  31. */
  32. #include <sys/feature_tests.h>
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /*
  37. * Basic / Extended integer types
  38. *
  39. * The following defines the basic fixed-size integer types.
  40. *
  41. * Implementations are free to typedef them to Standard C integer types or
  42. * extensions that they support. If an implementation does not support one
  43. * of the particular integer data types below, then it should not define the
  44. * typedefs and macros corresponding to that data type.  Note that int8_t
  45. * is not defined in -Xs mode on ISAs for which the ABI specifies "char"
  46. * as an unsigned entity because there is no way to define an eight bit
  47. * signed integral.
  48. */
  49. #if defined(_CHAR_IS_SIGNED)
  50. typedef char                    int8_t;
  51. #else
  52. #if defined(__STDC__)
  53. typedef signed char             int8_t;
  54. #endif
  55. #endif
  56. typedef short                   int16_t;
  57. typedef int                     int32_t;
  58. #ifdef  _LP64
  59. #define _INT64_TYPE
  60. typedef long                    int64_t;
  61. #else   /* _ILP32 */
  62. #if defined(_LONGLONG_TYPE)
  63. #define _INT64_TYPE
  64. typedef long long               int64_t;
  65. #endif
  66. #endif
  67. typedef unsigned char           uint8_t;
  68. typedef unsigned short          uint16_t;
  69. typedef unsigned int            uint32_t;
  70. #ifdef  _LP64
  71. typedef unsigned long           uint64_t;
  72. #else   /* _ILP32 */
  73. #if defined(_LONGLONG_TYPE)
  74. typedef unsigned long long      uint64_t;
  75. #endif
  76. #endif
  77. /*
  78. * intmax_t and uintmax_t are to be the longest (in number of bits) signed
  79. * and unsigned integer types supported by the implementation.
  80. */
  81. #if defined(_INT64_TYPE)
  82. typedef int64_t                 intmax_t;
  83. typedef uint64_t                uintmax_t;
  84. #else
  85. typedef int32_t                 intmax_t;
  86. typedef uint32_t                uintmax_t;
  87. #endif
  88. /*
  89. * intptr_t and uintptr_t are signed and unsigned integer types large enough
  90. * to hold any data pointer; that is, data pointers can be assigned into or
  91. * from these integer types without losing precision.
  92. */
  93. #if defined(_LP64) || defined(_I32LPx)
  94. typedef long                    intptr_t;
  95. typedef unsigned long           uintptr_t;
  96. #else
  97. typedef int                     intptr_t;
  98. typedef unsigned int            uintptr_t;
  99. #endif
  100. /*
  101. * The following define the fastest integer types that can hold the
  102. * specified number of bits.
  103. */
  104. #if defined(_CHAR_IS_SIGNED)
  105. typedef char                    int_fast8_t;
  106. #else
  107. #if defined(__STDC__)
  108. typedef signed char             int_fast8_t;
  109. #endif
  110. #endif
  111. typedef int                     int_fast16_t;
  112. typedef int                     int_fast32_t;
  113. #ifdef  _LP64
  114. typedef long                    int_fast64_t;
  115. #else   /* _ILP32 */
  116. #if defined(_LONGLONG_TYPE)
  117. typedef long long               int_fast64_t;
  118. #endif
  119. #endif
  120. typedef unsigned char           uint_fast8_t;
  121. typedef unsigned int            uint_fast16_t;
  122. typedef unsigned int            uint_fast32_t;
  123. #ifdef  _LP64
  124. typedef unsigned long           uint_fast64_t;
  125. #else   /* _ILP32 */
  126. #if defined(_LONGLONG_TYPE)
  127. typedef unsigned long long      uint_fast64_t;
  128. #endif
  129. #endif
  130. /*
  131. * The following define the smallest integer types that can hold the
  132. * specified number of bits.
  133. */
  134. #if defined(_CHAR_IS_SIGNED)
  135. typedef char                    int_least8_t;
  136. #else
  137. #if defined(__STDC__)
  138. typedef signed char             int_least8_t;
  139. #endif
  140. #endif
  141. typedef short                   int_least16_t;
  142. typedef int                     int_least32_t;
  143. #ifdef  _LP64
  144. typedef long                    int_least64_t;
  145. #else   /* _ILP32 */
  146. #if defined(_LONGLONG_TYPE)
  147. typedef long long               int_least64_t;
  148. #endif
  149. #endif
  150. typedef unsigned char           uint_least8_t;
  151. typedef unsigned short          uint_least16_t;
  152. typedef unsigned int            uint_least32_t;
  153. #ifdef  _LP64
  154. typedef unsigned long           uint_least64_t;
  155. #else   /* _ILP32 */
  156. #if defined(_LONGLONG_TYPE)
  157. typedef unsigned long long      uint_least64_t;
  158. #endif
  159. #endif
  160. #ifdef __cplusplus
  161. }
  162. #endif
  163. #endif /* _SYS_INT_TYPES_H */

c语言跨平台的实用技巧相关推荐

  1. 高端网站建设中多语言网站本地化的实用技巧

    企业会随着业务市场的不断扩大而发生与其他国家或地区合作的情况,对于企业来说这即是机遇也是挑战,想要获得成功的企业应该认真的思考这些问题.企业想要向国外市场发展自己的网站多语言化,并做到合理的本地化. ...

  2. 不思议迷宫c语言基础,不思议迷宫新手注意事项 新手实用技巧

    不思议迷宫是一款对新手不怎么友好的游戏,因此新手上手需要注意许多东西,那么一起来看看新手注意实行与实用技巧吧. 1,SL大法 分两种,小的是在你没有进门之前,退掉游戏,然后再上,这样可以刷新这一层的东 ...

  3. Vim 实用技术,第 1 部分: 实用技巧

    0. Vim 简介 作为开源世界最重要的编辑器之一(另一个是 Emacs),Vim 以其强大的功能和可定制能力被众多开发者所喜爱.不过,也许就是因为 Vim 的功能太强大了,要真正用好 Vim 并不容 ...

  4. Vim 实用技术,第 1 部分: 实用技巧(转)

    原文链接:http://blog.jobbole.com/20604/ 0. Vim 简介 作为开源世界最重要的编辑器之一(另一个是 Emacs),Vim 以其强大的功能和可定制能力被众多开发者所喜爱 ...

  5. Flutter完整开发实战详解(十七、 实用技巧与填坑二)

    作为系列文章的第十七篇,本篇再一次带来 Flutter 开发过程中的实用技巧,让你继续弯道超车,全篇均为个人的日常干货总结,以实用填坑为主,让你少走弯路狂飙车. Flutter 完整实战实战系列文章专 ...

  6. 深度学习11个实用技巧

    深度学习11个实用技巧 深度学习工程师George Seif发表了一篇博文,总结了7个深度学习的技巧,本文增加了几个技巧,总结了11个深度学习的技巧,主要从提高深度学习模型的准确性和速度两个角度来分析 ...

  7. 经典 | 深度学习的7大实用技巧

    编译 | AI科技大本营 参与 | 林椿眄 编辑 | 谷 磊 对于许多具有挑战性的现实问题,深度学习已经成为最有效的解决方法. 例如,对于目标检测,语音识别和语言翻译等问题,深度学习能够表现出最佳的性 ...

  8. 深度学习七个实用技巧

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 深度学习已经成为解决许多具有挑战性的现实世界问题的方法.对目标检测 ...

  9. Python大神用的贼溜,9个实用技巧分享给你

    来源:数据分析1480 本文约3000字,建议阅读6分钟 本文为你介绍一些关于python的实用技巧. 本文会试着介绍一些其它文章没有提到的小技巧,这些小技巧也是我平时会用到的的.让我们一探究竟吧! ...

最新文章

  1. 属于窄带噪声的是热噪声_时钟201系列: 非相位噪声的情况 (第一篇)
  2. Nature综述:真菌的多样性:真菌的高通量测序及鉴定
  3. 图形结构:安排课程,图的遍历策略
  4. Android 基本事件及对话框
  5. 笔记本电脑没有鼠标怎么右键_联想笔记本电脑没有声音怎么修复
  6. mysql格式分隔符row_MySQLRow格式Binlog的解析(1)
  7. LeetCode 110. 平衡二叉树(二叉树高度)
  8. 谈谈运维监控那些事儿
  9. charset参数 sqluldr2_大数据导出工具sqluldr2
  10. 分享一个原始传奇的辅助脚本
  11. BIM标准化系列写作思路
  12. neo4j中实现关键路径算法
  13. mac如何配置环境变量
  14. 调用微信方法报错errMsg:chooseImage:fail, the permission value is offline verifying
  15. 楚氏春秋(新版)第一部 风起平原
  16. 超简单的位运算---再也不用担心看不懂题解了
  17. EC200U open方案环境搭建
  18. epics安装css,EPICS-synApps/areaDetector安装
  19. black duck 下载_如何创建安全的Java软件:与Black Duck的Tim Mackey交谈
  20. 真的是成王败寇 现实如此残酷

热门文章

  1. 一个女人频繁做这些事,真的很爱你
  2. Linux和Windows误删文件恢复办法
  3. LockSupport的park和unpark的原理
  4. 智能汽车如何联接未来?岳麓峰会亮出“长沙梯度”
  5. 第二章(第三部分) 出发之前
  6. “三高病人”Verily和它背后的谷歌
  7. 孔子的名言,值得一生品读!
  8. 2021新年全屏标题动画素材ae模板
  9. 迈向图形化:dialog工具
  10. linux 蓝牙模块,蓝牙模块在HHARM2410上的移植