Currently GPC allows function results in `with' statements, as in:
program foo;
type a = record b, c: Integer end;
function f: a; begin f := a[b: 2; c: 3] end;
begin with f do WriteLn (b, c); end.
However, GPC currently also allows assignments to the components, such as:
with f do b := 2
which is quite clearly wrong.
Probably for this reasone, EP forbids function results in `with' statements at all (6.9.3.10: withÂelement = variableÂaccess | constantÂaccess.). I don't know about other dialects (BP has no records as result types, so the issue doesn't arise. What about Delphi etc.?).
At the moment, I'd tend to follow EP here and forbid them at all. Or does anyone think it's really necessary to have them? (Which would probably imply more work to make the fields read-only.)
Frank
On 22 Oct 2004 at 14:53, Frank Heckenbach wrote:
Currently GPC allows function results in `with' statements, as in:
program foo;
type a = record b, c: Integer end;
function f: a; begin f := a[b: 2; c: 3]
Delphi does not accept this. It gives this error: E:\temp\foo.pas(10) Error: '(' expected but '[' found E:\temp\foo.pas(10) Error: 'END' expected but ']' found
end;
begin with f do WriteLn (b, c); end.
However, GPC currently also allows assignments to the components, such as:
with f do b := 2
which is quite clearly wrong.
Delphi allows this, but the assignment actually achieves nothing. This is dangerous. Therefore, I agree that it should be forbidden.
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.greatchief.plus.com/
Prof A Olowofoyeku (The African Chief) a écrit:
On 22 Oct 2004 at 14:53, Frank Heckenbach wrote:
Currently GPC allows function results in `with' statements, as in:
program foo;
type a = record b, c: Integer end;
function f: a; begin f := a[b: 2; c: 3]
Delphi does not accept this. It gives this error: E:\temp\foo.pas(10) Error: '(' expected but '[' found
BP accepts only () not [] in initializers, and only in constants. gpc accepts both
Maurice
Prof A Olowofoyeku (The African Chief) wrote:
On 22 Oct 2004 at 14:53, Frank Heckenbach wrote:
Currently GPC allows function results in `with' statements, as in:
program foo;
type a = record b, c: Integer end;
function f: a; begin f := a[b: 2; c: 3]
Delphi does not accept this. It gives this error: E:\temp\foo.pas(10) Error: '(' expected but '[' found E:\temp\foo.pas(10) Error: 'END' expected but ']' found
Since several of you mentioned this, the issue was not about EP structured values -- any function returning a record will do (which BP doesn't allow, other compilers do).
Frank
Frank Heckenbach wrote:
Currently GPC allows function results in `with' statements, as in:
program foo;
type a = record b, c: Integer end;
function f: a; begin f := a[b: 2; c: 3] end;
MetroWerks CodeWarrior Pascal doesn't know this construction.
begin with f do WriteLn (b, c); end.
Allowed in MW Pascal.
However, GPC currently also allows assignments to the components, such as:
with f do b := 2
which is quite clearly wrong.
Allowed also (and wrong also).
Probably for this reasone, EP forbids function results in `with' statements at all (6.9.3.10: withelement = variableaccess | constantaccess.). I don't know about other dialects (BP has no records as result types, so the issue doesn't arise. What about Delphi etc.?).
At the moment, I'd tend to follow EP here and forbid them at all. Or does anyone think it's really necessary to have them? (Which would probably imply more work to make the fields read-only.)
Not a big issue for me.
Regards,
Adriaan van Os
On Fri, 22 Oct 2004, Frank Heckenbach wrote:
Probably for this reasone, EP forbids function results in `with' statements at all (6.9.3.10: withelement = variableaccess | constantaccess.). I don't know about other dialects (BP has no records as result types, so the issue doesn't arise. What about Delphi etc.?).
But pointers to records or objects are result types quite often. It seems to me that st. like
with foo(x)^ do ...
is useful in Delphi (or BP or FPC). As I understand it, the EP specification would forbid that too?
At the moment, I'd tend to follow EP here and forbid them at all. Or does anyone think it's really necessary to have them?
For Delphi and FPC compatibility it seems quite useful.
Josef
Josef Urban wrote:
On Fri, 22 Oct 2004, Frank Heckenbach wrote:
Probably for this reasone, EP forbids function results in `with' statements at all (6.9.3.10: withÂelement = variableÂaccess | constantÂaccess.). I don't know about other dialects (BP has no records as result types, so the issue doesn't arise. What about Delphi etc.?).
But pointers to records or objects are result types quite often. It seems to me that st. like
with foo(x)^ do ...
is useful in Delphi (or BP or FPC). As I understand it, the EP specification would forbid that too?
No, it allows it. That's not problematic since the pointer points to a more persistent object (record) which can meaningfully be modified etc. Whereas a function result just "disappears" after its use, so if that use is just an assignment, it's effectively meaningless.
Frank