COMPILE_ASSERT
// The COMPILE_ASSERT macro can be used to verify that a compile time
// expression is true. For example, you could use it to verify the
// size of a static array:
//
// COMPILE_ASSERT(ARRAYSIZE_UNSAFE(content_type_names) == CONTENT_NUM_TYPES,
// content_type_names_incorrect_size);
//
// or to make sure a struct is smaller than a certain size:
//
// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large);
//
// The second argument to the macro is the name of the variable. If
// the expression is false, most compilers will issue a warning/error
// containing the name of the variable.
template <bool>
struct CompileAssert {
};
#undef COMPILE_ASSERT
#define COMPILE_ASSERT(expr, msg) /
typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
// Implementation details of COMPILE_ASSERT:
//
// - COMPILE_ASSERT works by defining an array type that has -1
// elements (and thus is invalid) when the expression is false.
//
// - The simpler definition
//
// #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1]
//
// does not work, as gcc supports variable-length arrays whose sizes
// are determined at run-time (this is gcc's extension and not part
// of the C++ standard). As a result, gcc fails to reject the
// following code with the simple definition:
//
// int foo;
// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is
// // not a compile-time constant.
//
// - By using the type CompileAssert<(bool(expr))>, we ensures that
// expr is a compile-time constant. (Template arguments must be
// determined at compile-time.)
//
// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
//
// CompileAssert
//
// instead, these compilers will refuse to compile
//
// COMPILE_ASSERT(5 > 0, some_message);
//
// (They seem to think the ">" in "5 > 0" marks the end of the
// template argument list.)
//
// - The array size is (bool(expr) ? 1 : -1), instead of simply
//
// ((expr) ? 1 : -1).
//
// This is to avoid running into a bug in MS VC 7.1, which
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
주로 수조의 길이가 0보다 작으면 안 되는 특성을 사용했습니다. 예를 들어 inta[-1]는 컴파일할 때 오류가 발생합니다.각 컴파일러를 호환하기 위해 템플릿 기술을 사용했다.
msdn에서도 COMPILEASSERT:http://blogs.msdn.com/b/abhinaba/archive/2008/10/27/c-c-compile-time-asserts.aspx
boost에서 COMPILE와ASSERT는 BOOST 와 비슷합니다.STATIC_참조할 수 있는 ASSERT:http://www.boost.org/doc/libs/1_36_0/boost/static_assert.hpp
코드를 검색할 때 라이브러리mili(http://code.google.com/p/mili/), 이 안에도 하나의compileassert의 실현(http://code.google.com/p/mili/source/browse/trunk/include/compile_assert.h).이 라이브러리에는 Properties (http://code.google.com/p/mili/wiki/Properties).Properties의 실현 원리는 참고할 수 있다http://xiaolingyao.spaces.live.com/blog/cns!6A8F02D95D2DDE46!201.entry?sa=991256254.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Spring에서 속성 파일properties 읽기 및 사용 설명Spring에서 속성 파일properties 읽기 및 사용 설명 실제 프로젝트에서는 일반적으로 설정 가능한 맞춤형 정보를 속성 파일(예를 들어 데이터베이스 연결 정보, 메일 발송 설정 정보 등)에 넣으면 통일된 설정...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.