c语言跨平台的实用技巧
c语言在发展的历程中经历了c89和c99两个标准,为了实现c语言的跨平台的优点,就是在windows和Linux以及Unix上都可以执行,就需要进行一些跨平台的技巧了,但是不但c语言的标准多种多样,并且c语言的编译器也有很多种,gcc,lcc,vc++等,比如:对于int型有的编译器赋予4个字节,有的赋予2个字节。再次我给大家介绍一个好的技巧,就是inttypes.h头文件,这个头文件一般在编译器里边都有,#include<inttypes.h>以后就可以直接根据字节数目来定义变量而不是通过其他的.
以下是这个头文件在gcc编译器的代码,其他的类似
- bash-3.00$ vi int_types.h
- "int_types.h" [Read only] 176 lines, 4367 characters
- /*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
- #ifndef _SYS_INT_TYPES_H
- #define _SYS_INT_TYPES_H
- #pragma ident "@(#)int_types.h 1.10 04/09/28 SMI"
- /*
- * This file, <sys/int_types.h>, is part of the Sun Microsystems implementation
- * of <inttypes.h> defined in the ISO C standard, ISO/IEC 9899:1999
- * Programming language - C.
- *
- * Programs/Modules should not directly include this file. Access to the
- * types defined in this file should be through the inclusion of one of the
- * following files:
- *
- * <sys/types.h> Provides only the "_t" types defined in this
- * file which is a subset of the contents of
- * <inttypes.h>. (This can be appropriate for
- * all programs/modules except those claiming
- * ANSI-C conformance.)
- *
- * <sys/inttypes.h> Provides the Kernel and Driver appropriate
- * components of <inttypes.h>.
- *
- * <inttypes.h> For use by applications.
- *
- * See these files for more details.
- */
- #include <sys/feature_tests.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- /*
- * Basic / Extended integer types
- *
- * The following defines the basic fixed-size integer types.
- *
- * Implementations are free to typedef them to Standard C integer types or
- * extensions that they support. If an implementation does not support one
- * of the particular integer data types below, then it should not define the
- * typedefs and macros corresponding to that data type. Note that int8_t
- * is not defined in -Xs mode on ISAs for which the ABI specifies "char"
- * as an unsigned entity because there is no way to define an eight bit
- * signed integral.
- */
- #if defined(_CHAR_IS_SIGNED)
- typedef char int8_t;
- #else
- #if defined(__STDC__)
- typedef signed char int8_t;
- #endif
- #endif
- typedef short int16_t;
- typedef int int32_t;
- #ifdef _LP64
- #define _INT64_TYPE
- typedef long int64_t;
- #else /* _ILP32 */
- #if defined(_LONGLONG_TYPE)
- #define _INT64_TYPE
- typedef long long int64_t;
- #endif
- #endif
- typedef unsigned char uint8_t;
- typedef unsigned short uint16_t;
- typedef unsigned int uint32_t;
- #ifdef _LP64
- typedef unsigned long uint64_t;
- #else /* _ILP32 */
- #if defined(_LONGLONG_TYPE)
- typedef unsigned long long uint64_t;
- #endif
- #endif
- /*
- * intmax_t and uintmax_t are to be the longest (in number of bits) signed
- * and unsigned integer types supported by the implementation.
- */
- #if defined(_INT64_TYPE)
- typedef int64_t intmax_t;
- typedef uint64_t uintmax_t;
- #else
- typedef int32_t intmax_t;
- typedef uint32_t uintmax_t;
- #endif
- /*
- * intptr_t and uintptr_t are signed and unsigned integer types large enough
- * to hold any data pointer; that is, data pointers can be assigned into or
- * from these integer types without losing precision.
- */
- #if defined(_LP64) || defined(_I32LPx)
- typedef long intptr_t;
- typedef unsigned long uintptr_t;
- #else
- typedef int intptr_t;
- typedef unsigned int uintptr_t;
- #endif
- /*
- * The following define the fastest integer types that can hold the
- * specified number of bits.
- */
- #if defined(_CHAR_IS_SIGNED)
- typedef char int_fast8_t;
- #else
- #if defined(__STDC__)
- typedef signed char int_fast8_t;
- #endif
- #endif
- typedef int int_fast16_t;
- typedef int int_fast32_t;
- #ifdef _LP64
- typedef long int_fast64_t;
- #else /* _ILP32 */
- #if defined(_LONGLONG_TYPE)
- typedef long long int_fast64_t;
- #endif
- #endif
- typedef unsigned char uint_fast8_t;
- typedef unsigned int uint_fast16_t;
- typedef unsigned int uint_fast32_t;
- #ifdef _LP64
- typedef unsigned long uint_fast64_t;
- #else /* _ILP32 */
- #if defined(_LONGLONG_TYPE)
- typedef unsigned long long uint_fast64_t;
- #endif
- #endif
- /*
- * The following define the smallest integer types that can hold the
- * specified number of bits.
- */
- #if defined(_CHAR_IS_SIGNED)
- typedef char int_least8_t;
- #else
- #if defined(__STDC__)
- typedef signed char int_least8_t;
- #endif
- #endif
- typedef short int_least16_t;
- typedef int int_least32_t;
- #ifdef _LP64
- typedef long int_least64_t;
- #else /* _ILP32 */
- #if defined(_LONGLONG_TYPE)
- typedef long long int_least64_t;
- #endif
- #endif
- typedef unsigned char uint_least8_t;
- typedef unsigned short uint_least16_t;
- typedef unsigned int uint_least32_t;
- #ifdef _LP64
- typedef unsigned long uint_least64_t;
- #else /* _ILP32 */
- #if defined(_LONGLONG_TYPE)
- typedef unsigned long long uint_least64_t;
- #endif
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif /* _SYS_INT_TYPES_H */
c语言跨平台的实用技巧相关推荐
- 高端网站建设中多语言网站本地化的实用技巧
企业会随着业务市场的不断扩大而发生与其他国家或地区合作的情况,对于企业来说这即是机遇也是挑战,想要获得成功的企业应该认真的思考这些问题.企业想要向国外市场发展自己的网站多语言化,并做到合理的本地化. ...
- 不思议迷宫c语言基础,不思议迷宫新手注意事项 新手实用技巧
不思议迷宫是一款对新手不怎么友好的游戏,因此新手上手需要注意许多东西,那么一起来看看新手注意实行与实用技巧吧. 1,SL大法 分两种,小的是在你没有进门之前,退掉游戏,然后再上,这样可以刷新这一层的东 ...
- Vim 实用技术,第 1 部分: 实用技巧
0. Vim 简介 作为开源世界最重要的编辑器之一(另一个是 Emacs),Vim 以其强大的功能和可定制能力被众多开发者所喜爱.不过,也许就是因为 Vim 的功能太强大了,要真正用好 Vim 并不容 ...
- Vim 实用技术,第 1 部分: 实用技巧(转)
原文链接:http://blog.jobbole.com/20604/ 0. Vim 简介 作为开源世界最重要的编辑器之一(另一个是 Emacs),Vim 以其强大的功能和可定制能力被众多开发者所喜爱 ...
- Flutter完整开发实战详解(十七、 实用技巧与填坑二)
作为系列文章的第十七篇,本篇再一次带来 Flutter 开发过程中的实用技巧,让你继续弯道超车,全篇均为个人的日常干货总结,以实用填坑为主,让你少走弯路狂飙车. Flutter 完整实战实战系列文章专 ...
- 深度学习11个实用技巧
深度学习11个实用技巧 深度学习工程师George Seif发表了一篇博文,总结了7个深度学习的技巧,本文增加了几个技巧,总结了11个深度学习的技巧,主要从提高深度学习模型的准确性和速度两个角度来分析 ...
- 经典 | 深度学习的7大实用技巧
编译 | AI科技大本营 参与 | 林椿眄 编辑 | 谷 磊 对于许多具有挑战性的现实问题,深度学习已经成为最有效的解决方法. 例如,对于目标检测,语音识别和语言翻译等问题,深度学习能够表现出最佳的性 ...
- 深度学习七个实用技巧
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 深度学习已经成为解决许多具有挑战性的现实世界问题的方法.对目标检测 ...
- Python大神用的贼溜,9个实用技巧分享给你
来源:数据分析1480 本文约3000字,建议阅读6分钟 本文为你介绍一些关于python的实用技巧. 本文会试着介绍一些其它文章没有提到的小技巧,这些小技巧也是我平时会用到的的.让我们一探究竟吧! ...
最新文章
- 属于窄带噪声的是热噪声_时钟201系列: 非相位噪声的情况 (第一篇)
- Nature综述:真菌的多样性:真菌的高通量测序及鉴定
- 图形结构:安排课程,图的遍历策略
- Android 基本事件及对话框
- 笔记本电脑没有鼠标怎么右键_联想笔记本电脑没有声音怎么修复
- mysql格式分隔符row_MySQLRow格式Binlog的解析(1)
- LeetCode 110. 平衡二叉树(二叉树高度)
- 谈谈运维监控那些事儿
- charset参数 sqluldr2_大数据导出工具sqluldr2
- 分享一个原始传奇的辅助脚本
- BIM标准化系列写作思路
- neo4j中实现关键路径算法
- mac如何配置环境变量
- 调用微信方法报错errMsg:chooseImage:fail, the permission value is offline verifying
- 楚氏春秋(新版)第一部 风起平原
- 超简单的位运算---再也不用担心看不懂题解了
- EC200U open方案环境搭建
- epics安装css,EPICS-synApps/areaDetector安装
- black duck 下载_如何创建安全的Java软件:与Black Duck的Tim Mackey交谈
- 真的是成王败寇 现实如此残酷