Cross Platform Note: STD C++ Preprocessor directives & pre-defined macros
ref: http://www.cplusplus.com/doc/tutorial/preprocessor/
concolusion:
directives:
#define #undef
#include
#if #else #elif #endif #ifdef #ifndef
#error ( #warning is NOT A STANDARD DIRECTIVE, since not shown in the page above, but most compilers have it. more: http://stackoverflow.com/questions/171435/portability-of-warning-preprocessor-directive )
#line
#pragma ( all compiler support #pragma to set options, but "These options are specific for the platform and the compiler you use.", so no standard options.)
macros:
__LINE__
__FILE__
__DATE__
__TIME__
(__FUNCTION__ is NOT STANDARD MACRO. __FUNCTION__ is defined on both MSVC & GCC; GCC better use __PRETTY_FUNCTION__. c99 has standard __func__)
__cplusplus (has a value to identifying C++98 / 11 )
__STD_HOSTED__
optional: __STDC__ __STDC_VERSION__ __STDC_MB_MIGHT_NEQ_WC__ __STDC_ISO_10646__ __STDCPP_STRICT_POINTER_SAFETY__ __STDCPP_THREADS__
Example of use non standard macros (compiler specific) in Blade:
/********************************************************************
created: 2009/02/07
filename: Platform.h
author: Crazii purpose: the platform dependent definitions
*********************************************************************/
#ifndef __Blade_Platform_h__
#define __Blade_Platform_h__ /************************************************************************/
/* processor unit */
/************************************************************************/
#define BLADE_PROCESSOR_X86 (0)
#define BLADE_PROCESSOR_IA64 (1)
#define BLADE_PROCESSOR_PPC (2)
#define BLADE_PROCESSOR_ARM (3) #if defined ARM || defined __arm__ || defined _ARM
# define BLADE_PROCESSOR BLADE_PROCESSOR_ARM #elif defined __ia64 || defined _M_IA64 || defined __ia64__
# define BLADE_PROCESSOR BLADE_PROCESSOR_IA64 #elif defined __X86__ || defined __i386__ || defined i386 || defined _M_IX86 || defined __386__ || defined __x86_64__ || defined _M_X64
# define BLADE_PROCESSOR BLADE_PROCESSOR_X86 #elif defined __PPC__ || defined __POWERPC__ || defined powerpc || defined _POWER || defined __ppc__ || defined __powerpc__ || defined _M_PPC
# define BLADE_PROCESSOR BLADE_PROCESSOR_PPC #else
# error "processor not supported yet."
#endif /************************************************************************/
/* this is the system specific,windows and linux, etc */
/************************************************************************/ #define BLADE_PLATFORM_WINDOWS (0)
#define BLADE_PLATFORM_WINPHONE (1) #define BLADE_PLATFORM_LINUX (2)
#define BLADE_PLATFORM_ANDROID (3)
#define BLADE_PLATFORM_IOS (4)
#define BLADE_PLATFORM_MAC (5) #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) # define BLADE_PLATFORM BLADE_PLATFORM_WINDOWS #elif defined(WP8) && defined(_WP8) # define BLADE_PLATFORM BLADE_PLATFORM_WINPHONE #elif defined(ANDROID) || defined(__ANDROID__)//since android will also define __linux__, we need check android first #define BLADE_PLATFORM BLADE_PLATFORM_ANDROID #elif defined(__linux__) # define BLADE_PLATFORM BLADE_PLATFORM_LINUX #else
# error "current system not support yet."
#endif //Careful on using those class system definition. different system may have different APIs.
//i.e. Unix POSIX version difference, windows Desktop/Mobile API differences. #if defined(__unix__)
# define BLADE_IS_UNIX_CLASS_SYSTEM
#else
# define BLADE_IS_UNIX_CLASS_SYSTEM
#endif #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) || defined(_WIN32_WCE) || defined(WINRT) || defined(_WINRT) || defined(WP8) || defined(_WP8)
# define BLADE_IS_WINDOWS_CLASS_SYSTEM
#else
# define BLADE_IS_WINDOWS_CLASS_SYSTEM
#endif /************************************************************************/
/* Architecture (32/64 bit) */
/************************************************************************/ #define BLADE_ARCHITECTURE_32BIT (0)
#define BLADE_ARCHITECTURE_64BIT (1) #if defined(__x86_64__) || defined(_M_X64) || defined(_M_IA64) || defined(_M_AMD64) || defined(__powerpc64__) || defined(__alpha__) || defined(__ia64__) || defined(__s390__) || defined(__s390x__)
# define BLADE_ARCHITECTURE BLADE_ARCHITECTURE_64BIT
# define BLADE_MEMORY_ALIGNMENT ()
#else
# define BLADE_ARCHITECTURE BLADE_ARCHITECTURE_32BIT
# define BLADE_MEMORY_ALIGNMENT ()
#endif /************************************************************************/
/* this is the compiler specific ,MSVC and GCC currently supported */
/************************************************************************/
#define BLADE_COMPILER_MSVC (0)
#define BLADE_COMPILER_GNUC (1) #if defined(_MSC_VER)
# define BLADE_COMPILER BLADE_COMPILER_MSVC
# define BLADE_ALIGNED(n) __declspec(align(n))
# define BLADE_CDECL __cdecl
# define BLADE_STDCALL __stdcall
# define BLADE_FASTCALL __fastcall
# define BLADE_FUNCTION __FUNCTION__
# define BLADE_ALLWAYS_INLINE __forceinline
#elif defined(__GNUC__)
# define BLADE_COMPILER BLADE_COMPILER_GNUC
# define BLADE_ALIGNED(n) __attribute__((aligned(n)))
# define BLADE_CDECL __attribute__((cdecl))
# define BLADE_STDCALL __attribute__((stdcall))
# define BLADE_FASTCALL __attribute__((fastcall))
# define BLADE_FUNCTION __PRETTY_FUNCTION__
# define BLADE_ALLWAYS_INLINE __attribute__((always_inline))
#else
# error "Compiler not supported yet."
# define BLADE_ALLWAYS_INLINE inline
#endif #if defined(_DEBUG) || defined(DEBUG)
# define BLADE_DEBUG
#else
# define BLADE_DEBUG
#endif #define BLADE_ENDIAN_LITTLE 0
#define BLADE_ENDIAN_BIG 1 //endian macros
//HOWTO: ARM processor can have dynamic endian with endian map, how to check? #if BLADE_PROCESSOR == BLADE_PROCESSOR_X86 || \
BLADE_PROCESSOR == BLADE_PROCESSOR_ARM #define BLADE_ENDIAN BLADE_ENDIAN_LITTLE #else #define BLADE_ENDIAN BLADE_ENDIAN_BIG #endif //make unicode macro having a value
#if defined(UNICODE) || defined(_UNICODE)
# undef UNICODE
# define UNICODE
# define BLADE_UNICODE
#else
# define BLADE_UNICODE
#endif #endif // __Blade_Platform_h__
Cross Platform Note: STD C++ Preprocessor directives & pre-defined macros的更多相关文章
- “CMake”这个名字是“cross platform make”
cmake_百度百科 https://baike.baidu.com/item/cmake/7138032?fr=aladdin CMake 可以编译源代码.制作程序库.产生适配器(wrapper). ...
- V4 Reduce Transportable Tablespace Downtime using Cross Platform Incremental Backup (Doc ID 2471245.1)
V4 Reduce Transportable Tablespace Downtime using Cross Platform Incremental Backup (Doc ID 2471245. ...
- Comparing Xamarin and Delphi XE5 to Xcode for Cross Platform Mobile App Development
Comparing Xamarin and Delphi XE5 to Xcode for Cross Platform Mobile App Development If you are consi ...
- Gtest:Using visual studio 2017 cross platform feature to compile code remotely
参考:使用Visual Studio 2017作为Linux C++开发工具 前言 最近在学Gtest单元测试框架,由于平时都是使用Source Insight写代码,遇到问题自己还是要到Linux下 ...
- Cross platform GUI for creating SSL certs with OpenSSL
Someone said: from : https://micksmix.wordpress.com/2012/08/09/xca-cross-platform-gui-for-creating-s ...
- Cross platform
值得学习的C/C++语言开源项目 (1)ACE 庞大.复杂,适合大型项目.开源.免费,不依赖第三方库,支持跨平台. http://www.cs.wustl.edu/~schmidt/ACE.html ...
- Qt编程之Qt样例表(QSS)
For a long time, Qt has allowed you to decorate your GUIs with CSS’ish style sheets. Inspired by the ...
- c++11-17 模板核心知识(二)—— 类模板
类模板声明.实现与使用 Class Instantiation 使用类模板的部分成员函数 Concept 友元 方式一 方式二 类模板的全特化 类模板的偏特化 多模板参数的偏特化 默认模板参数 Typ ...
- Visual Studio 2015 Pre Secondary Installer 在哪里
安装vs2015 pre后,会自动打开Secondary Installer, 用于Cross Platform的移动开发框架,包括Cordova插件.若安装失败,启动程序位置: "D:\P ...
随机推荐
- select、poll、epoll的区别
本文写于2017-02-26,从老账号迁移到本账号,原文地址:https://www.cnblogs.com/huangweiyang/p/6444746.html select.poll.epoll ...
- ftp远端上的文件下载
用linux下的wge下t载比在window下一个个点方便多了,命令如下: wget ftp:// 110.110.110/\*.mseed --ftp-user=username --ftp-pas ...
- 谱聚类(Spectral Clustring)原理
谱聚类(spectral clustering)是广泛使用的聚类算法,比起传统的K-Means算法,谱聚类对数据分布的适应性更强,聚类效果也很优秀,同时聚类的计算量也小很多,更加难能可贵的是实现起来也 ...
- PTA-栈(括弧匹配)
#include<bits/stdc++.h> using namespace std; #define STACK_INIT_SIZE 10000 #define STACKINCREM ...
- 本地操作功能 --local_action
Ansible 默认只会对控制机器执行操作,但如果在这个过程中需要在 Ansible 本机执行操作呢?细心的读者可能已经想到了,可以使用 delegate_to( 任务委派 ) 功能呀.没错,是可以使 ...
- C#连接字符串
1."Data Source=服务器名; Initial Catalog=数据库; User ID =用户名; Password=密码; Charset=UTF8; " 2.&qu ...
- 周强 201771010141《面对对象程序设计(java)》第十周学习总结
---恢复内容开始--- 1.实验目的与要求 (1) 理解泛型概念: (2) 掌握泛型类的定义与使用: (3) 掌握泛型方法的声明与使用: (4) 掌握泛型接口的定义与实现: (5)了解泛型程序设计, ...
- CentOS Linux 升级内核步骤和方法(转)
当前系统为CentOS Linux release 6.0 (Final),内核版本为2.6.32-71.el6.i686.由于最近内核出现最新的漏洞(linux kernel 又爆内存提权漏洞,2. ...
- Linux 驱动——Button驱动7(Timer)消抖
button_drv.c驱动文件: #include <linux/module.h>#include <linux/kernel.h>#include <linux/f ...
- CnPack组件包的安装与使用
如果你用过Eclipse.NotePad++等等工具,再试试用刚装好Delphi写代码会很痛苦,你是否觉得Delphi的代码编辑器很不友好? 那就去了解一下CnPack吧,给你的Delphi装上它绝对 ...