🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fj.lang.pascal
Article #166

Re: Pascalのunion

#166
From: Tomohiko Sakamoto
Date: Wed, 24 Sep 1997 00:00
68 lines
2367 bytes
In article <3427C7AC.225B4D2B@hi-net.or.jp>,
	Masakatsu Kudoh <masak@hi-net.or.jp> writes:
> $B!!#C8@8l$G(B union $B$H$$$&6&MQBN$,$"$j$^$7$?$h$M!#$?$7$+0J2<$N%W%m%0%i%`(B
> $B$NMM$J46$8$N!#(B
> 
> typedef struct
> {
>     unsigned int  WORD_DATA;
>     union
>     {
>         unsigned char WORD_HI;
>         unsigned char WORD_LO;
>     };
> } Sample;
> 
> $B!!@5$7$$=q$-J}!JJ8K!!K$OK:$l$^$7$?$,!"$3$N>l9g!"(B

$B@5$7$$=q$-J}$O!"(B

main()
{
    union {
        short WORD_DATA;
        struct { unsigned char WORD_HI, WORD_LO; } s;
    } Sample;

    Sample.WORD_DATA = 0x0501;
    printf("Sample.s.WORD_HI = 0x%02x\n", Sample.s.WORD_HI);
    printf("Sample.s.WORD_LO = 0x%02x\n", Sample.s.WORD_LO);
    printf("Sample.WORD_DATA = 0x%04x\n", Sample.WORD_DATA);
    return 0;
}

$B$?$@$7!"(BIntel$B$N(B CPU$B$N$h$&$K%j%H%k%(%s%G%#%"%s$@$H!"(BWORD_HI $B$H(B WORD_LO
$B$,5U$K$J$k$H;W$$$^$9!#(B


> $B$H$$$&7k2L$K$J$j$^$9$h$M!"$?$7$+!#$3$l$r!"$^$?$O$3$l$K;w$?J}K!$r(B
> Delphi 3.0 $B$G$G$-$^$;$s$G$7$g$&$+!)(B
> $B!!$G$-$l$P%5%s%W%k$r2C$($F$$$?$@$1$l$P=u$+$j$^$9!#(B

Delphi $B$OCN$i$J$$$N$G!"(BNEWS-OS 4.x $B$d(B NEWS-OS 6.x $B$N(B Pascal $B$G$N%5%s(B
$B%W%k$r5s$2$F$_$^$7$g$&!#(Binteger $B$O(B 4$B%P%$%H$G%S%C%0%(%s%G%#%"%s$G$9!#(B

program main(output);
var
    sample :
        record
            case integer of
            0: ( word : integer );
            1: ( byte0, byte1, byte2, byte3 : char );
        end;
begin
    sample.word := 4097;
    writeln(ord(sample.byte0), ord(sample.byte1),
            ord(sample.byte2), ord(sample.byte3));
    sample.byte0 := chr(0);  sample.byte1 := chr(1);
    sample.byte2 := chr(0);  sample.byte3 := chr(3);
    writeln(sample.word)
end.

$B<B9T7k2L$O!"(B
         0         0        16         1
     65539

--
$B:dK\CRI'(B	sakamoto@sm.sony.co.jp
Technical Details
Message-ID: <60a3ea$iqe@csdnews.sm.sony.co.jp>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3427C7AC.225B4D2B@hi-net.or.jp>

Show Full Headers
Complete Article Headers
X-Google-Language: Japanese,JIS
X-Google-Thread: ff90a,41ce56e12aa187d5
X-Google-Attributes: gidff90a,public
From: sakamoto@sm.sony.co.jp (Tomohiko Sakamoto)
Subject: Re: Pascalのunion
Date: 1997/09/24
Message-ID: <60a3ea$iqe@csdnews.sm.sony.co.jp>
X-Deja-AN: 275125878
References: <3427C7AC.225B4D2B@hi-net.or.jp>
Organization: ITC, Sony Corporation
Reply-To: sakamoto@sm.sony.co.jp
Newsgroups: fj.lang.pascal