except10.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 53 行
C
53 行
#include "fail.h"
// 93/11/18 (jww) fixed on 10.0 (not on 9.5)
// reported by a customer (AFS)
/* Watcom 9.5, patch A: Executing the "for" loop causes Foo's constructor
to be called 4 times (correct), and its destructor to be called
1 time (oops).
Seems to be independent of -d1 or -d2, optimizer flags, etc.
*/
#include <stdio.h>
unsigned count;
class Foo
{
public:
Foo(int);
~Foo();
int x() const;
private:
int x_;
};
Foo::Foo(int x) : x_(x)
{
++count;
}
Foo::~Foo()
{
--count;
}
int Foo::x() const
{
return x_;
}
Foo func()
{
return Foo(3);
}
int main(int, char**)
{
for (int i = 0 ; i < func().x() ; i++)
{
}
if( count != 0 ) fail(__LINE__);
_PASS;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?