tw16004.pp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. {$apptype console}
  2. {$mode Delphi}
  3. {$assertions on}
  4. {$codepage cp1251}
  5. function verify(const p; const size: integer; const z: array of byte): boolean;
  6. begin
  7. assert( size = length(z)*sizeof(z[0]) );
  8. result := CompareByte(p, z[0], size) = 0;
  9. writeln(result)
  10. end;
  11. procedure foo;
  12. var a: array[0..5] of char = 'willow';
  13. const b: array[0..2] of WideChar = 'èâà';
  14. begin
  15. assert( verify(a, sizeof(a), [ord('w'), ord('i'), ord('l'), ord('l'), ord('o'), ord('w')]) );
  16. {$ifdef endian_big}
  17. assert( verify(b, sizeof(b), [$04,$38,$04,$32,$04,$30]) )
  18. {$else}
  19. assert( verify(b, sizeof(b), [$38,$04,$32,$04,$30,$04]) )
  20. {$endif}
  21. end;
  22. const c: array[0..10] of char = 'rosenberg';
  23. var d: array[0..10] of WideChar = 'ðîçåíáåðã';
  24. z: array[0..1] of WideChar = 'û';
  25. x: array[0..0] of char = 'x';
  26. begin
  27. assert( verify(c, sizeof(c), [114, 111, 115, 101, 110, 98, 101, 114, 103, 0, 0]) );
  28. {$ifdef endian_big}
  29. assert( verify(d, sizeof(d), [$04,$40,$04,$3E,$04,$37,$04,$35,$04,$3D,$04,$31,$04,$35,$04,$40,$04,$33,0,0,0,0]) );
  30. {$else}
  31. assert( verify(d, sizeof(d), [$40,$04,$3E,$04,$37,$04,$35,$04,$3D,$04,$31,$04,$35,$04,$40,$04,$33,$04,0,0,0,0]) );
  32. {$endif}
  33. foo;
  34. {$ifdef endian_big}
  35. assert( verify(z, sizeof(z), [$04,$4B,0,0]) );
  36. {$else}
  37. assert( verify(z, sizeof(z), [$4B,$04,0,0]) );
  38. {$endif}
  39. assert( verify(x, sizeof(x), [120]) )
  40. end.