pack03.c

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

C
35
字号
#include "fail.h"

typedef unsigned long dword;
typedef unsigned short word;
typedef unsigned char byte;

union s_ebx {
   dword _ebx;
   word  _bx;
   struct {
       byte  _bl;
       byte  _bh;
   };
};

void foo( union s_ebx *p )
{
    p->_ebx = 0x01020304;
    p->_bx = 0x0506;
    p->_bh = 0x07;
    p->_bl = 0x08;
}

int main()
{
    union s_ebx reg;

    foo( &reg );
    if( reg._ebx != 0x01020708 ) fail(__LINE__);
    if( reg._bx != 0x708 ) fail(__LINE__);
    if( reg._bh != 0x07 ) fail(__LINE__);
    if( reg._bl != 0x08 ) fail(__LINE__);
    _PASS;
}

⌨️ 快捷键说明

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