让爱一切成空歌词并发断⾔及时断⾔区别_唯⼀断⾔并发断⾔ 及时断⾔区别
Asrtions are very helpful to find problems or bugs. But, sometimes there's a problem
断⾔对于发现问题或错误⾮常有帮助。 但是,有时候会有问题
using them, for example within a loop or a very often called function, becau if such an
使⽤它们,例如在循环中或经常调⽤的函数中使⽤,因为如果
asrtion fails it may happen that tons of asrtion-dialogs pop up (at least in VC++
断⾔失败,可能会弹出⼤量断⾔对话框(⾄少在VC ++中)
with 'ASSERT'-macro that's quite a mess).
与“ ASSERT”宏⾮常混乱)。
The following macro can be ud easily just the same way as VC++'s 'ASSERT'-macro or
可以很容易地使⽤以下宏,就像VC ++的“ ASSERT”宏或
CRT's 'asrt'. To make its usage thread-safe first I introduce a simple class which does
日语在线翻译exciteCRT的“断⾔”。 为了使它的使⽤成为线程安全的,我⾸先介绍⼀个简单的类
synchronization using a mutex in Windows - if you want to u the macro with other
在Windows中使⽤互斥锁进⾏同步-如果要与其他宏⼀起使⽤
OS you'll have to adapt that class:
操作系统,您必须适应该类:
class Lock
{
HANDLE GetMutex()
{
static HANDLE hMutex = ::CreateMutex( NULL, FALSE, NULL );
return hMutex;
}
public:
Lock()
{
::WaitForSingleObject( GetMutex(), INFINITE );
}
~Lock()
{
::ReleaMutex( GetMutex() );
}
};
Here's the macro itlf:
这是宏本⾝:
// Handle the first time the asrtion fails
#define asrt_once_out_first( x ) \
std::cout << __FILE__ << "(" << __LINE__ << "): first asrtion for expression '" << #x << "'" << std::endl; // Handle further asrtion fails
#define asrt_once_out_next( x ) \2008年考研英语真题
std::cout << __FILE__ << "(" << __LINE__ << "): known asrtion for expression '" << #x << "'" << std::endl; // Generates a file-wide unique variable name
#define asrt_once_var __bAsrted__ ## __LINE__ ## __
// The unique asrt macro
#define asrt_once( x ) \
do { \
Lock _lock; \
static bool asrt_once_v = fal; \
if ( !(x) ) \
{ \
if ( !asrt_once_v ) \
{ \
初中语文知识点总结asrt_once_v = true; \
asrt_once_out_first( x ); \
} \
el \
{ \
asrt_once_out_next( x ); \
} \
} \
} while ( 0 )
The usage is just simple, i.e.:
⽤法很简单,即:
hound dog> int _tmain( int argc, char* argv[] )
> int _tmain(int argc,char * argv [])
> {
> {
> for ( int i = 0; i < 3; i++ )
>对于(int i = 0; i <3; i ++)
> {
> {scar
> asrt_once( i < 2 );
> asrt_once(i <2);
>
>
> for ( int j = 0; j < 3; j++ )
>对于(int j = 0; j <3; j ++)
英文qq名> {
> {
> asrt_once( j % 2 != 1 );life is a struggle
> asrt_once(j%2!= 1);
> }
>}
美国mba课程> }
>}
造价工程师报考条件>
>
>
>
> return -1;
>返回-1;
>}
>}
The output will be:
输出将是:
> c:\test\testasrt.cpp(15): first asrtion for expression 'j % 2 != 1'
> c:\ test \ testasrt.cpp(15) :表达式'j%2!= 1'的第⼀个断⾔
> c:\test\testasrt.cpp(15): known asrtion for expression 'j % 2 != 1'
> c:\ test \ testasrt.cpp(15) :表达式'j%2!= 1'的已知断⾔
> c:\test\testasrt.cpp(11): first asrtion for expression 'i < 2'
> c:\ test \ testasrt.cpp(11) :表达式'i <2'的第⼀个断⾔
> c:\test\testasrt.cpp(15): known asrtion for expression 'j % 2 != 1'
> c:\ test \ testasrt.cpp(15) :表达式'j%2!= 1'的已知断⾔
For VC++ it's even simple to u the macros ASSERT and TRACE by just replacing the 对于VC ++,只需替换这些宏即可使⽤ASSERT和TRACE宏
two macros as shown here:
两个宏,如下所⽰:
> #define asrt_once_out_first( x ) \
> #define asrt_once_out_first(x)\
> TRACE( "%s(%d): Asrtion for expression '%s'\n", __FILE__, __LINE__, #x ); \
> TRACE(“%s(%d):表达式'%s'\ n”的断⾔,__FILE__,__LINE__,#x); \
> ASSERT( x );
> ASSERT(x);
>
>
> #define asrt_once_out_next( x ) \
> #define asrt_once_out_next(x)\
> TRACE( "%s(%d): Known asrtion for expression '%s'\n", __FILE__, __LINE__, #x ); \ > TRACE(“%s(%d):表达式'%s'\ n的已知断⾔,__FILE__,__LINE__,#x); \
并发断⾔ 及时断⾔区别