Forwarded message from marcov@stack.nl (Marco van de Voort):
Hmm, this is starting to become a daily routine, BUT, I couldn't pass by Waldek "initialised variables" subject without a few comments, you can throw this msg on the list.
(note this is all from memory, and I'm not even a compiler guy, so check it yourself. Just to get you on the trail)
Note that the reason the example fails in any mode but delphi is simply that the integer size=16-bit in those modes. (BP compat)
[And the routine must be declared `far' in BP AFAIR. -- Frank]
If you correct the program by - substituting longint for integer - adding () to the bar call. - use normal mode (no params) or objfpc mode (-S2)
then the program works in a recent (1.9.9) version, but I think this is pretty invariant within 1.9.x.
The delphi case fails, afaik out of compability.
The rules for FPC are simple (though there might be gotcha's, or changed things) is to roughly follow delphi, but
- when in doubt allow () to force function call. - when in doubt use @ to force assignment of proc variable.
FPC modi use/require a '@' a lot more than Delphi mode to resolve ambiguity. IIRC Delphi also knows @@ to take the address of the procvar itself.
Delphi has a lot of special rules with respect to procvars and methodvars. The FPC testsuite probably contains quite a few.
program bug1; {$X+} type tfunc = function : pointer; function baz : longint; begin baz := 1024 * 2; end; var bar : tfunc; function foo : longint; begin foo := longint(@baz); // force assignment. end; begin bar := tfunc (foo); { this is where Delphi and BP barf } writeln (longint (bar())); // force call end.