Bug? Delphi-style result variable
Hi Folks, compiling the program Program Test; var x: integer; Function foo: integer; Procedure bar; begin (* bar *) result:= 7; end (* bar *); begin (* foo *) bar; end (* foo *); begin x:= foo; end. yields an error message test.pas: In procedure `bar': test.pas:14: error: invalid access to `Result' test.pas: In function `foo': test.pas:20: error: result of function not assigned Bug or feature? Yours, Markus
Markus Gerwinski wrote:
compiling the program
Program Test;
var x: integer;
Function foo: integer;
Procedure bar; begin (* bar *) result:= 7; end (* bar *);
begin (* foo *) bar; end (* foo *);
begin x:= foo; end.
yields an error message
test.pas: In procedure `bar': test.pas:14: error: invalid access to `Result' test.pas: In function `foo': test.pas:20: error: result of function not assigned
Bug or feature?
Feature. The program is flat out wrong and gpc is telling you how and where. Replace "result" with "bar" in bar, and "bar" with "foo = bar" in foo, and it should compile and run. -- "If you want to post a followup via groups.google.com, don't use the broken "Reply" link at the bottom of the article. Click on "show options" at the top of the article, then click on the "Reply" at the bottom of the article headers." - Keith Thompson
Markus Gerwinski wrote:
compiling the program
Program Test;
var x: integer;
Function foo: integer;
Procedure bar; begin (* bar *) result:= 7; end (* bar *);
begin (* foo *) bar; end (* foo *);
begin x:= foo; end.
yields an error message
test.pas: In procedure `bar': test.pas:14: error: invalid access to `Result' test.pas: In function `foo': test.pas:20: error: result of function not assigned
Bug or feature?
An interesting case indeed. Since `Result' is a Delphi feature, we probably should check if Delphi allows this, and if so do so as well. Notice, though, that if it does, it's somewhat confusing (if both `foo' and `bar' are functions, one implicit `Result' probably shadows the other -- please try this case with Delphi as well), and error-prone (in your example, if you later decide to make `bar' a function with an integer type result, the code would silently change its meaning). BTW, Chuck, I'm well aware that you prefer to use only ISO 7185 features, and if that's ok for you, fine. But it's really not necessary to point this out each time someone mentions an feature of ISO 10206 or another dialect. Why don't you save yourself the annoyance and just skip such threads? Frank -- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE D101 CD02 4C9D 0FE0 E5E8
Frank Heckenbach dixit:
Function foo: integer; Procedure bar;
Notice, though, that if it does, it's somewhat confusing (if both `foo' and `bar' are functions
But they aren't in this example, which both you and CBFalconer seemed to not have seen. bye, //mirabile --
[...] Echtzeit hat weniger mit "Speed"[...] zu tun, sondern damit, daß der richtige Prozeß voraussagbar rechtzeitig sein Zeitscheibchen bekommt. Wir haben uns[...] geeinigt, dass das verwendete Echtzeit-Betriebssystem[...] weil selbst einfachste Operationen *echt* *Zeit* brauchen. (aus d.a.s.r)
Thorsten Glaser wrote:
Frank Heckenbach dixit:
Function foo: integer; Procedure bar;
Notice, though, that if it does, it's somewhat confusing (if both `foo' and `bar' are functions
But they aren't in this example, which both you and CBFalconer seemed to not have seen.
OK, you don't only know what I get or don't get, now you also know what I saw or didn't see? (I'll leave it to Chuck to reply for himself if he bothers, though I can't see even remotely what this comment has do to with his previous reply.) But if you read further what I wrote, you could notice:
[...], one implicit `Result' probably shadows the other -- please try this case with Delphi as well),
Any idea what I could have meant by writing "if" and "this case *as well*"? Frank -- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE D101 CD02 4C9D 0FE0 E5E8
On 9 Feb 2005 at 8:10, Markus Gerwinski wrote:
Hi Folks,
compiling the program
Program Test;
var x: integer;
Function foo: integer;
Procedure bar; begin (* bar *) result:= 7; end (* bar *);
begin (* foo *) bar; end (* foo *);
begin x:= foo; end.
yields an error message
test.pas: In procedure `bar': test.pas:14: error: invalid access to `Result' test.pas: In function `foo': test.pas:20: error: result of function not assigned
Bug or feature?
The program should compile, because it compiles under Delphi, and the "Result" stuff is there for Delphi compatibility (although I think that Delphi should really not compile such a thing, that is beside the point). Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
participants (5)
-
CBFalconer -
Frank Heckenbach -
Markus Gerwinski -
Prof A Olowofoyeku (The African Chief) -
Thorsten Glaser