tb0157.pp 948 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. { Old file: tbs0188.pp }
  2. { can't print function result of procedural var that returns a function. Not a bugs : wrong syntax !! See source (PM) }
  3. { this are no bugs, just wrong
  4. understanding of FPC syntax }
  5. type testfunc = function:longint;
  6. var f : testfunc;
  7. var test: testfunc;
  8. function test_temp: longint;
  9. begin
  10. test_temp:=12;
  11. end;
  12. procedure sound(test: testfunc);
  13. begin
  14. {writeln(test); this is wrong because
  15. test is the function itself and write does not know how to
  16. output a function !
  17. to call test you must use test() !! }
  18. writeln(test());
  19. end; { proc. sound }
  20. var i : longint;
  21. begin
  22. i:=test_temp;
  23. f:=@test_temp;
  24. if f()<>i then
  25. begin
  26. Writeln('error calling f');
  27. Halt(1);
  28. end;
  29. { this works for FPC
  30. sound(test_temp);
  31. but the correct syntax would be }
  32. sound(@test_temp);
  33. { imagine if a function would return its own type !! }
  34. { for f var this is correct also ! }
  35. sound(f);
  36. end.