talign2.pp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. {$mode objfpc}
  19. procedure test(b : boolean);
  20. begin
  21. if b then exit;
  22. WriteLn('Error in length/alignment!!');
  23. halt(1);
  24. end;
  25. var
  26. pt: pchar;
  27. const
  28. b: byte = 0; { lets just misalign the stuff }
  29. p : pchar = 'simple pchar stuff';
  30. ansistr : ansistring = 'simple ansistring';
  31. {$ifdef haswidestring}
  32. widestr : widestring = 'simple widestring';
  33. {$endif}
  34. shortstr :shortstring = 'simple shortstring';
  35. begin
  36. test(length(ansistr)=17);
  37. {$ifdef haswidestring}
  38. test(length(widestr)=17);
  39. {$endif}
  40. test(length(shortstr)=18);
  41. { verify if the address are correctly aligned! }
  42. pt:=@shortstr;
  43. test((cardinal(pt) mod sizeof(pointer))=0);
  44. pt:=p;
  45. test((cardinal(pt) mod sizeof(pointer))=0);
  46. pt:=pchar(ansistr);
  47. test((cardinal(pt) mod sizeof(pointer))=0);
  48. {$ifdef haswidestring}
  49. pt:=pchar(widestr);
  50. test((cardinal(pt) mod sizeof(pointer))=0);
  51. {$endif}
  52. end.
  53. {
  54. $Log$
  55. Revision 1.2 2002-11-09 21:19:21 carl
  56. * now check address of tc's also and give error.
  57. + 1.1 only
  58. Revision 1.1 2002/11/09 13:18:25 carl
  59. * more alignment checking
  60. }