⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logic.c

📁 Small Device C Compiler 面向Inter8051
💻 C
字号:
/** Tests the basic logical operations.    type: char, int, long    storage: static,     attr: volatile    values: 5, 350, 31734 */#include <testfwk.h>static {type}alwaysTrue(void){    return ({type}){values};}static {type}alwaysFalse(void){    return 0;}static {type}neverGetHere(void){    FAILM("Shouldn't get here");    return 0;}static int hit;static voidresetGetHere(void){    hit = 0;}static {type}alwaysGetHere(void){    hit++;    return 1;}static voidtestLogicalAnd(void){    {type} true = alwaysTrue();    {type} false = alwaysFalse();    ASSERT(true && true && true);    ASSERT(true && !false);    ASSERT(!false && true);    /* Test that the evaluation is aborted on the first false. */    if (true && false && neverGetHere()) {        /* Tested using neverGetHere() */    }    /* Alternate that is similar. */    if (true && false) {        neverGetHere();        /* Tested using neverGetHere() */    }    resetGetHere();    /* Test that the evaluation is done left to right. */    if (alwaysGetHere() && true && false) {        ASSERT(hit == 1);    }}static voidtestLogicalOr(void){    {type} true = alwaysTrue();    {type} false = alwaysFalse();    ASSERT(false || false || true);    ASSERT(!true || !false);    ASSERT(false || true);    /* Test that the evaluation is aborted on the first hit. */    if (false || true || neverGetHere()) {        /* Tested using neverGetHere() */    }    resetGetHere();    /* Test that the evaluation is done left to right. */    if (alwaysGetHere() || true || false) {        ASSERT(hit == 1);    }}static voidtestNot(void){    {type} true = alwaysTrue();    {type} false = alwaysFalse();    ASSERT(!false);    ASSERT(!!true);    ASSERT(!!!false);}static voidtestFlagToVariable(void){    {type} true = alwaysTrue();    {type} false = alwaysFalse();    {type} val = !true;    ASSERT(!val);    val = !!false;    ASSERT(!false);}

⌨️ 快捷键说明

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