- Код: Выделить всё
 typedef union{
short W;
struct{
byte l,h;
} B;
} word;
Можно ли что-то похожее сделать на pascal?
Модератор: Модераторы
typedef union{
  short W;
  struct{
      byte l,h;
  } B;
} word;
type
  TUnion = record
     case byte of
       1:(W:short);
       2:(h,l:byte);
     end
  end
type
  TB = record
     h,l:byte;
  end;
 TUnion = record
     W:short;
     B:TB;
  end;
var
  word:TUnion;Type
  TUnion = record
    W: ShortInt;
    TB: record
       h,l: Byte;
    End;
End;
#include <stdio.h>
typedef union{ 
  short W; 
  struct{ 
      unsigned char l,h; 
  } B; 
} word;
main(){
  word A;
  A.B.l = 0x10;
  A.B.h = 0x20;
  printf("%x", A.W);
  return 0;
}
//EOF
bash#./test
bash#2010
type
  TB = record
     h,l:byte;
  end;
 TUnion = record
     W : word;
     B : TB;
  end;
var
  wrd : TUnion;
begin
  wrd.B.l := 10;
  wrd.B.h := 20;
  writeln(wrd.W);
  readln;
end.
#./test
#0
type
  TUnion = record
  case Boolean of
    False: (W: Word);
    True : (B: record
      l, h: Byte;
    end);
  end;
var
  U: TUnion;
begin
  U.B.l := $10;
  U.B.h := $20;
  WriteLn(HexStr(U.W, 4));
end.
type
  TUnion = packed record
  case Size: Byte of
    1: (B: record l, h: Byte; end);
    2: (W: Word);
  end;
var
  U: TUnion;
begin
  WriteLn(SizeOf(U));
  U.Size := 2;
  U.B.l := $10;
  U.B.h := $20;
  WriteLn('Word: ', HexStr(U.W, 4));
  WriteLn('Size: ', U.Size);
end.Сейчас этот форум просматривают: Google [Bot] и гости: 1