`
raojl
  • 浏览: 204006 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

编译校验【代码笔记】

阅读更多

 

1、版本编译控制(比如多项目)

2、编译校验

3、static_cast

----------------------------------------------------------

 

// static_check.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>

using namespace std;

namespace Loki
{
////////////////////////////////////////////////////////////////////////////////
// Helper structure for the STATIC_CHECK macro
////////////////////////////////////////////////////////////////////////////////

    template<int> struct CompileTimeError;
    template<> struct CompileTimeError<true> {};
}

////////////////////////////////////////////////////////////////////////////////
// macro STATIC_CHECK
// Invocation: STATIC_CHECK(expr, id)
// where:
// expr is a compile-time integral or pointer expression
// id is a C++ identifier that does not need to be defined
// If expr is zero, id will appear in a compile-time error message.
////////////////////////////////////////////////////////////////////////////////

#define STATIC_CHECK(expr, msg) \
    { Loki::CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; } 

int _tmain(int argc, _TCHAR* argv[])
{
	STATIC_CHECK((sizeof(int) == 4 && sizeof(long) == 4), 32bit);
	STATIC_CHECK((sizeof(int) != sizeof(long)), 64bit);
	return 0;
}

  ////////////////////////////////////////////////////////////////////////////////

// The Loki Library
// Copyright (c) 2001 by Andrei Alexandrescu
// This code accompanies the book:
// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design 
//     Patterns Applied". Copyright (c) 2001. Addison-Wesley.
// Permission to use, copy, modify, distribute and sell this software for any 
//     purpose is hereby granted without fee, provided that the above copyright 
//     notice appear in all copies and that both that copyright notice and this 
//     permission notice appear in supporting documentation.
// The author or Addison-Welsey Longman make no representations about the 
//     suitability of this software for any purpose. It is provided "as is" 
//     without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////

// Last update: November 22, 2001

#ifndef TYPEMANIP_INC_
#define TYPEMANIP_INC_

namespace Loki
{
////////////////////////////////////////////////////////////////////////////////
// class template Int2Type
// Converts each integral constant into a unique type
// Invocation: Int2Type<v> where v is a compile-time constant integral
// Defines 'value', an enum that evaluates to v
////////////////////////////////////////////////////////////////////////////////

    template <int v>
    struct Int2Type
    {
        enum { value = v };
    };
    
////////////////////////////////////////////////////////////////////////////////
// class template Type2Type
// Converts each type into a unique, insipid type
// Invocation Type2Type<T> where T is a type
// Defines the type OriginalType which maps back to T
////////////////////////////////////////////////////////////////////////////////

    template <typename T>
    struct Type2Type
    {
        typedef T OriginalType;
    };
    
////////////////////////////////////////////////////////////////////////////////
// class template Select
// Selects one of two types based upon a boolean constant
// Invocation: Select<flag, T, U>::Result
// where:
// flag is a compile-time boolean constant
// T and U are types
// Result evaluates to T if flag is true, and to U otherwise.
////////////////////////////////////////////////////////////////////////////////

    template <bool flag, typename T, typename U>
    struct Select
    {
        typedef T Result;
    };
    template <typename T, typename U>
    struct Select<false, T, U>
    {
        typedef U Result;
    };
    
////////////////////////////////////////////////////////////////////////////////
// class template IsSameType
// Return true iff two given types are the same
// Invocation: SameType<T, U>::value
// where:
// T and U are types
// Result evaluates to true iff U == T (types equal)
////////////////////////////////////////////////////////////////////////////////

    template <typename T, typename U>
    struct IsSameType
    {
        enum { value = false };
    };
    
    template <typename T>
    struct IsSameType<T,T>
    {
        enum { value = true };
    };

////////////////////////////////////////////////////////////////////////////////
// Helper types Small and Big - guarantee that sizeof(Small) < sizeof(Big)
////////////////////////////////////////////////////////////////////////////////

    namespace Private
    {
        template <class T, class U>
        struct ConversionHelper
        {
            typedef char Small;
            struct Big { char dummy[2]; };
            static Big   Test(...);
            static Small Test(U);
            static T MakeT();
        };
    }

////////////////////////////////////////////////////////////////////////////////
// class template Conversion
// Figures out the conversion relationships between two types
// Invocations (T and U are types):
// a) Conversion<T, U>::exists
// returns (at compile time) true if there is an implicit conversion from T
// to U (example: Derived to Base)
// b) Conversion<T, U>::exists2Way
// returns (at compile time) true if there are both conversions from T
// to U and from U to T (example: int to char and back)
// c) Conversion<T, U>::sameType
// returns (at compile time) true if T and U represent the same type
//
// Caveat: might not work if T and U are in a private inheritance hierarchy.
////////////////////////////////////////////////////////////////////////////////

    template <class T, class U>
    struct Conversion
    {
        typedef Private::ConversionHelper<T, U> H;
#ifndef __MWERKS__
        enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) };
#else
        enum { exists = false };
#endif
        enum { exists2Way = exists && Conversion<U, T>::exists };
        enum { sameType = false };
    };
    
    template <class T>
    struct Conversion<T, T>    
    {
        enum { exists = 1, exists2Way = 1, sameType = 1 };
    };
    
    template <class T>
    struct Conversion<void, T>    
    {
        enum { exists = 0, exists2Way = 0, sameType = 0 };
    };
    
    template <class T>
    struct Conversion<T, void>    
    {
        enum { exists = 0, exists2Way = 0, sameType = 0 };
    };
    
    template <>
    struct Conversion<void, void>    
    {
    public:
        enum { exists = 1, exists2Way = 1, sameType = 1 };
    };

////////////////////////////////////////////////////////////////////////////////
// class template SuperSubclass
// Invocation: SuperSubclass<B, D>::value where B and D are types. 
// Returns true if B is a public base of D, or if B and D are aliases of the 
// same type.
//
// Caveat: might not work if T and U are in a private inheritance hierarchy.
////////////////////////////////////////////////////////////////////////////////

template <class T, class U>
struct SuperSubclass
{
  enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists &&
                  !::Loki::Conversion<const volatile T*, const volatile void*>::sameType) };
};

////////////////////////////////////////////////////////////////////////////////
// class template SuperSubclassStrict
// Invocation: SuperSubclassStrict<B, D>::value where B and D are types. 
// Returns true if B is a public base of D.
//
// Caveat: might not work if T and U are in a private inheritance hierarchy.
////////////////////////////////////////////////////////////////////////////////

template<class T,class U>
struct SuperSubclassStrict
{
  enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists &&
                 !::Loki::Conversion<const volatile T*, const volatile void*>::sameType &&
                 !::Loki::Conversion<const volatile T*, const volatile U*>::sameType) };
};

}   // namespace Loki

////////////////////////////////////////////////////////////////////////////////
// macro SUPERSUBCLASS
// Invocation: SUPERSUBCLASS(B, D) where B and D are types. 
// Returns true if B is a public base of D, or if B and D are aliases of the 
// same type.
//
// Caveat: might not work if T and U are in a private inheritance hierarchy.
// Deprecated: Use SuperSubclass class template instead.
////////////////////////////////////////////////////////////////////////////////

#define SUPERSUBCLASS(T, U) \
    ::Loki::SuperSubclass<T,U>::value

////////////////////////////////////////////////////////////////////////////////
// macro SUPERSUBCLASS_STRICT
// Invocation: SUPERSUBCLASS(B, D) where B and D are types. 
// Returns true if B is a public base of D.
//
// Caveat: might not work if T and U are in a private inheritance hierarchy.
// Deprecated: Use SuperSubclassStrict class template instead.
////////////////////////////////////////////////////////////////////////////////

#define SUPERSUBCLASS_STRICT(T, U) \
    ::Loki::SuperSubclassStrict<T,U>::value

////////////////////////////////////////////////////////////////////////////////
// Change log:
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
// November 22, 2001: minor change to support porting to boost
// November 22, 2001: fixed bug in Conversion<void, T>
//      (credit due to Brad Town)
// November 23, 2001: (well it's 12:01 am) fixed bug in SUPERSUBCLASS - added
//      the volatile qualifier to be 100% politically correct
// September 16, 2002: Changed "const volatile" to "const volatile *", to enable
//     conversion to succeed. Done earlier by MKH.
//     Added SuperSubclass and SuperSubclassStrict templates. The corresponding
//     macros are deprecated.
//     Added extra parenthesis in sizeof in Conversion, to disambiguate function
//     call from function declaration. T.S.
////////////////////////////////////////////////////////////////////////////////

#endif // TYPEMANIP_INC_
 

 

分享到:
评论

相关推荐

    c#学习笔记.txt

    c#学习笔记(1) 51099在线学习网发布 文章来源:网络收集 发布时间:2006-05-25 字体: [大 中 小] 51099在线学习网 http://www.51099.com 1, 结构(struct) 与 类(class) [attributes] [modifiers] struct ...

    软考中级软件设计师笔记.zip

    软考中级软件设计师学习笔记 World版本 下载后可直接打印作为2020年上半年考试的复习资料用 1.CPU 的功能的功能:程序控制、操作控制、时间控制、数据处理。 2.计算机系统组成示意图计算机系统组成示意图: 3....

    第五版软件设计师笔记

    7.常用校验码:奇偶校验码(只能检错)、海明码(纠错加检错)、循环冗余校验码( CRC)。 8.计算机体系结构分类:单处理系统,并行处理与多处理系统,分布式处理系统。 9.指令集的发展:CISC(复杂指令集计算机):...

    day020-继承加强和设计模式代码和笔记.rar

    该文件夹类型是source folder类型,源文件夹,eclipse工具会自动编译 --------------------------------------------------------------------------------- 传统方式获取流是new创建的,而在web开发中有...

    android笔记.rar

    1.3 编译在G1 上运行的android 2.1(eclair)代码 ... ..9 1.4 编译在G1 上运行的android 2.2(froyo)代码_旧方法... ..12 1.5 编译在G1 上运行的android 2.2(froyo)代码_新方法... ..15 1.6 编译在N1 上运行的android ...

    struts项目学习笔记

    基于AOP(面向切面编程)思想的拦截器机制,更易扩展(不修改源代码的条件下,增强代码功能) 更强大、更易用输入校验功能 整合Ajax支持:json插件 Struts2的今生前世: 1.早期开发模型Servlet+JSP+JavaBean显得...

    2010年谢彦的android笔记

    1.3 编译在G1上运行的android 2.1(eclair)代码 9 1.4 编译在G1上运行的android 2.2(froyo)代码_旧方法 12 1.5 编译在G1上运行的android 2.2(froyo)代码_新方法 15 1.6 编译在N1上运行的android 2.3(GingerBread)代码...

    php学习笔记

    DTD校验 16 在xml文件中引入dtd文件的两种方式 17 DTD元素和修饰符 17 元素属性列表说明 17 实体定义分两种 18 使用php对xml文件进行操作 19 CSS 23 margin 26 element 28 box 29 position 31 apache 34 ...

    CRC-manipulator:更改文件的CRC校验和

    笔记 该存储库不再维护。 重点已转移到该工具的(性能相当)。 特征 修补和计算以下内容的CRC校验和: CRC32 CRC32POSIX(来自GNU coreutils的cksum ) CRC16CCITT CRC16IBM 适用于GNU / Linux和Windows。 ...

    webpack学习笔记之优化缓存、合并、懒加载

    除了的webpack基本配置,还可以进一步添加配置,优化合并文件,加快编译速度。下面是生产环境配置文件webpack.production.js,与wenbpack.config.js相比其不需要一些dev-tools,dev-server和jshint校验等,将与开发...

    OpenWRT_B70_SPI_16M:硬改过的B70适用

    编译笔记参考使用GitHub Actions构建OpenWrt说明硬改SPI闪存后的硬件规格和youku-L2以及newifi-D1相近,主要参考其中的dts文件配置来拼凑。通过星级出发动作实现云端编译。U盘中文乱码 , , LEDE下该方法无效,可以...

    asp.net知识库

    ASP.NET 2.0 中的代码隐藏和编译 ASP.NET 2.0 Language Swithcer and Theme Swicher 多语言转换和多样式主题转换 ASP.NET2.0 ObjectDataSource的使用详解(1) ASP.NET2.0 ObjectDataSource的使用详解(2) ...

    超级软件工具箱

    01.MD5校验工具 02.获取上网帐号并保存到D盘 03.Flash播放器 04.isodisk(多镜像虚拟光驱) 05.UltraISO(刻录工具) 06.定时关机 07.红烛教鞭 08.畸形目录修改 09.默认安装路径修改器 10.资料转移工具 ...

    【软件加密_技术内幕】

    [Trial version] 利用DebugAPI做一些原先手工完成的动作,我用这种方法做过内存补丁,内存注册机等,完全VC编译.htm [Trial version] 第4章 Windows下的异常处理 [Trial version] 4.1 基本概念 [Trial version] ...

    Scripts:一些有用的脚本在这里

    使用方法 python terminalcolors.py 检测终端(XTerm)的颜色支持,用于校验是否能够使用256色配色方案,如果能够输出各种颜色,证明功能正常clean_compile_soft.py --&gt; 清理编译安装的软件,有些软件的 Makefile...

    黑苹果优化神器,驱动打包

    &gt; Disable ECC Memory:给AppleTyMCEDriver驱动打补丁,修复MacPro机型因ECC内存校验出现错误 &gt; Bluetooth commandWakeup:给IOBluetoothHostControllerUSBTransport驱动打补丁,修复启动/唤醒 时出现 “Bluetooth...

    ant_junitc测试

    为了督促自己学习,同时也是为了及时总结,并与大家分享,近期准备写一个mybatis学习笔记的系列博文。请有兴趣的朋友多多关注、督促并批评指正!不胜感激! 在拙作《纯手工编写第一个Hibernate程序》和《对“纯...

    《Linux从入门到精通》

    E.5.3 Red Hat Linux是否包含源代码? E.6 安装 E.6.1 我有一个空的硬盘, 并想安装DOS或Windows 95和Linux. 最好的方法是什么? E.6.2 我没有CD-ROM, 也不能从网上安装. 是否有其他方法? E.6.3 我想制作新的软盘, ...

    Linux从入门到精通

    E.5.3 Red Hat Linux是否包含源代码? E.6 安装 E.6.1 我有一个空的硬盘, 并想安装DOS或Windows 95和Linux. 最好的方法是什么? E.6.2 我没有CD-ROM, 也不能从网上安装. 是否有其他方法? E.6.3 我想制作新的软盘, ...

    2005详细介绍Linux从入门到精通

    E.5.3 Red Hat Linux是否包含源代码? E.6 安装 E.6.1 我有一个空的硬盘, 并想安装DOS或Windows 95和Linux. 最好的方法是什么? E.6.2 我没有CD-ROM, 也不能从网上安装. 是否有其他方法? E.6.3 我想制作新的软盘, ...

Global site tag (gtag.js) - Google Analytics