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

📄 init22.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
字号:
#include "fail.h"
#include <stdlib.h>
#include <string.h>

int fni( int a );

/* Test initialization of _Bool objects */

// any non-zero scalar gets converted to 1
_Bool ab[] = {
    32,
    0x20,
    3.1415,
    2.2f,
    (void *)4,
    ab,
    &ab,
    (void (*)()) 4,
    fni,
    0x2000000000,
};

// any zero scalar gets converted to 0:
_Bool cd[] = {
    0,
    0x0,
    0.000,
    0.0f,
    (void *)0,
    (void (*)()) 0,
    0x0000ULL,
    0LL
};

// Expressions using _Bool are compile-time constants:
char ef[(_Bool) -0.5 == 1 ? 1 : -1];
char gh[(_Bool) -0.0 == 0 ? 1 : -1];

// _Bool works as a struct element and bitfield type:
struct ij {
    _Bool i: 1;
    _Bool j;
} ij;

int fni( int a )
{
    _Bool   b = a;

    return( b );
}

int fnd( double a )
{
    _Bool   b = a;

    return( b );
}

int fnp( void *a )
{
    _Bool   b = a;

    return( b );
}

int main( void )
{
    char    *b;

    // note - ISO standard doesn't guarantee that sizeof( _Bool ) is 1
    b = (char *)ab;
    for( int i = 0; i < sizeof( ab ) / sizeof( ab[0] ); ++i ) {
        if( b[i] != 1 ) fail( __LINE__ );
    }

    if( fni( 42 ) + fnd( 6.28 ) + fnp( &main ) != 3 ) fail( __LINE__ );
    _PASS;
}

⌨️ 快捷键说明

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