talign2.pp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. { %VERSION=1.1 }
  2. {%OPT=-Og}
  3. { This verifies if the strings are
  4. correctly aligned, normally the generated assembler
  5. should be verified manually.
  6. }
  7. program talign2;
  8. {$ifdef fpc}
  9. {$mode objfpc}
  10. {$ifndef ver1_0}
  11. {$define haswidestring}
  12. {$endif}
  13. {$else}
  14. {$ifndef ver70}
  15. {$define haswidestring}
  16. {$endif}
  17. {$endif}
  18. procedure test(b : boolean);
  19. begin
  20. if b then exit;
  21. WriteLn('Error in length/alignment!!');
  22. halt(1);
  23. end;
  24. var
  25. pt: pchar;
  26. const
  27. b: byte = 0; { lets just misalign the stuff }
  28. p : pchar = 'simple pchar stuff';
  29. ansistr : ansistring = 'simple ansistring';
  30. {$ifdef haswidestring}
  31. widestr : widestring = 'simple widestring';
  32. {$endif}
  33. shortstr :shortstring = 'simple shortstring';
  34. begin
  35. test(length(ansistr)=17);
  36. {$ifdef haswidestring}
  37. test(length(widestr)=17);
  38. {$endif}
  39. test(length(shortstr)=18);
  40. { verify if the address are correctly aligned! }
  41. pt:=@shortstr;
  42. test((ptruint(pt) mod sizeof(pointer))=0);
  43. pt:=p;
  44. test((ptruint(pt) mod sizeof(pointer))=0);
  45. pt:=pchar(ansistr);
  46. test((ptruint(pt) mod sizeof(pointer))=0);
  47. {$ifdef haswidestring}
  48. pt:=pchar(widestr);
  49. test((ptruint(pt) mod sizeof(pointer))=0);
  50. {$endif}
  51. end.