stat01.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 52 行

C
52
字号
#include "fail.h"
#include <stdlib.h>

#if __WATCOM_REVISION__ >= 8

struct S : _CD {
    static int d;
    static int foo( int x );
};
int S::d;

static S * volatile p;

int side_effect;

int i;
S *a[20];
S *side_effect1( int x ) {
    ++side_effect;
    rand();
    return a[x];
}

S &side_effect2( int x ) {
    ++side_effect;
    rand();
    return *a[x];
}

int S::foo( int x ) {
    return x + d;
}

int main() {
    a[1] = new S;
    p->d = 1;
    if( p->foo( 1 ) != 2 ) fail(__LINE__);
    (i=0,side_effect1(++i))->d = 2;
    if( side_effect != 1 ) fail(__LINE__);
    if( (i=0,side_effect1(++i))->foo( 2 ) != 4 ) fail(__LINE__);
    if( side_effect != 2 ) fail(__LINE__);
    (i=0,side_effect2(++i)).d = 3;
    if( side_effect != 3 ) fail(__LINE__);
    if( (i=0,side_effect2(++i)).foo( 3 ) != 6 ) fail(__LINE__);
    if( side_effect != 4 ) fail(__LINE__);
    delete a[1];
    _PASS;
}
#else
ALWAYS_PASS
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?