Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Jonas Maebe
Graeme Geldenhuys wrote on do, 19 nov 2009: Jonas Maebe wrote: Delphi compatibility. And Delphi does that because COM requires this behaviour. Can't that behaviour be limited to Windows platform only. It would change the behaviour of code between Windows and non-Windows platforms. One

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Alexander Klenin
On Thu, Nov 19, 2009 at 18:36, Jonas Maebe jonas.ma...@elis.ugent.be wrote: More importantly, another thing it would affect is that in case someone has written their own fillchar with an out parameter, and *expects* reference counted structures to be finalised at the caller side before they

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Jonas Maebe
Alexander Klenin wrote on do, 19 nov 2009: On Thu, Nov 19, 2009 at 18:36, Jonas Maebe jonas.ma...@elis.ugent.be wrote: More importantly, another thing it would affect is that in case someone has written their own fillchar with an out parameter, and *expects* reference counted structures to be

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Florian Klaempfl
Graeme Geldenhuys schrieb: Florian Klaempfl wrote: Without COM, FPC wouldn't have out parameters. Why do you say that? Because I added it for Delphi compatibility which needs it for COM? I see many use-cases for out parameters You mean for VAROUT parameters :)?

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Martin
Jonas Maebe wrote: Alexander Klenin wrote on do, 19 nov 2009: Can you give an example code which would be (badly) affected by proposed change? type tr = record str: ansistring; end; procedure clear(out rec; size: ptruint); begin fillchar(rec,size,0); end; var r: tr; begin

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Graeme Geldenhuys
Florian Klaempfl wrote: I see many use-cases for out parameters You mean for VAROUT parameters :)? I search the latest FP Language Reference document, and there is no mention of 'varout'. I also tried to use varout in a procedure as follows - which gave a compiler error with FPC 2.4.0-rc1

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Graeme Geldenhuys
Alexander Klenin wrote: Can you give an example code which would be (badly) affected by proposed change? Thanks Alexander, you beat me to that question. :-) Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Vincent Snijders
Graeme Geldenhuys schreef: Florian Klaempfl wrote: I see many use-cases for out parameters You mean for VAROUT parameters :)? First one is not compilable, but the second one is. So no, I don't understand your comment about 'varout'? Please explain more. varout could be the name of the

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Florian Klaempfl
Graeme Geldenhuys schrieb: Florian Klaempfl wrote: I see many use-cases for out parameters You mean for VAROUT parameters :)? I search the latest FP Language Reference document, and there is no mention of 'varout'. I also tried to use varout in a procedure as follows - which gave a

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Florian Klaempfl
Vincent Snijders schrieb: Graeme Geldenhuys schreef: Florian Klaempfl wrote: I see many use-cases for out parameters You mean for VAROUT parameters :)? First one is not compilable, but the second one is. So no, I don't understand your comment about 'varout'? Please explain more.

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Graeme Geldenhuys
Vincent Snijders wrote: varout could be the name of the new parameter modifier that Jonas mentions[1] and that has the semantics that you think out should have, but hasn't. Ah, now I understand. Thanks Vincent. Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Graeme Geldenhuys
Florian Klaempfl wrote: initialized. But be warned: with such a parameter type you can easily create memory leaks with automated types like ansistrings. Well, isn't that what heaptrc is for? I enable heaptrc by default for all my projects (except on release builds). That way I can catch

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Marc Weustink
Graeme Geldenhuys wrote: Florian Klaempfl wrote: initialized. But be warned: with such a parameter type you can easily create memory leaks with automated types like ansistrings. Well, isn't that what heaptrc is for? No, the language should protect you from such easy to make mistakes. In

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Paul Ishenin
Graeme Geldenhuys wrote: As I stated in the other mailing list. It's not about a obsession to get hint warning free code. It's about spoting REAL issues in code between all the crap the compiler currently spits out. If your project uses a lot of structure types, you can quickly sit with

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Florian Klaempfl
Paul Ishenin schrieb: Graeme Geldenhuys wrote: As I stated in the other mailing list. It's not about a obsession to get hint warning free code. It's about spoting REAL issues in code between all the crap the compiler currently spits out. If your project uses a lot of structure types, you

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Graeme Geldenhuys
Marc Weustink wrote: Well, isn't that what heaptrc is for? No, the language should protect you from such easy to make mistakes. I guess that's the ideal situation. Currently the language doesn't stop me from creating other memory leaks like not freeing a TStringList or other object

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Alexander Klenin
I still do not fully understand. On Thu, Nov 19, 2009 at 19:20, Martin laza...@mfriebe.de wrote: Jonas Maebe wrote: [skipped example] Well in this case, the code is actually positively affected by the out param (because it avoids the mem leak) Jonas, can you confirm that your example is

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Graeme Geldenhuys
Paul Ishenin wrote: Compiler will add a flag for each var/const argument that they dont require that checks. Can't the compiler simply initialize structured types by default? Initialize char arrays to empty strings, other structures like pointers to nil, byte arrays to #0 etc..? After all,

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Jonas Maebe
On 19 Nov 2009, at 11:21, Alexander Klenin wrote: On Thu, Nov 19, 2009 at 19:20, Martin laza...@mfriebe.de wrote: Jonas Maebe wrote: [skipped example] Well in this case, the code is actually positively affected by the out param (because it avoids the mem leak) Jonas, can you confirm

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Thaddy
Jonas Maebe wrote: If you change the behaviour of out so that such parameters are no longer finalised before the routine is entered, then the above will cause a memory leak. You can verify this by changing the out rec parameter into var rec. Then this is definitely not a sextopod but an

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Martin
Jonas Maebe wrote: On 19 Nov 2009, at 11:21, Alexander Klenin wrote: Well in this case, the code is actually positively affected by the out param (because it avoids the mem leak) Jonas, can you confirm that your example is incorrect one, and Martin's example below is actually what you

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Marco van de Voort
In our previous episode, Graeme Geldenhuys said: initialized. But be warned: with such a parameter type you can easily create memory leaks with automated types like ansistrings. Well, isn't that what heaptrc is for? I enable heaptrc by default for all my projects (except on release

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Alexander Klenin
On Thu, Nov 19, 2009 at 20:31, Jonas Maebe jonas.ma...@elis.ugent.be wrote: On 19 Nov 2009, at 11:21, Alexander Klenin wrote: On Thu, Nov 19, 2009 at 19:20, Martin laza...@mfriebe.de wrote: Jonas Maebe wrote: [skipped example] Well in this case, the code is actually positively affected

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Jonas Maebe
On 19 Nov 2009, at 11:24, Graeme Geldenhuys wrote: Paul Ishenin wrote: Compiler will add a flag for each var/const argument that they dont require that checks. Can't the compiler simply initialize structured types by default? The compiler already initialises the reference counted fields

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Jonas Maebe
On 19 Nov 2009, at 11:39, Thaddy wrote: Jonas Maebe wrote: If you change the behaviour of out so that such parameters are no longer finalised before the routine is entered, then the above will cause a memory leak. You can verify this by changing the out rec parameter into var rec.

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Jonas Maebe
On 19 Nov 2009, at 11:42, Alexander Klenin wrote: No, I asked for an example of code that would be negatively affected by changing var to out in FillChar parameter. I don't know by heart anymore, but as I mentioned the compiler crashed when I tried that (or if you did that move, which

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Alexander Klenin
On Thu, Nov 19, 2009 at 20:46, Jonas Maebe jonas.ma...@elis.ugent.be wrote: On 19 Nov 2009, at 11:42, Alexander Klenin wrote: No, I asked for an example of code that would be negatively affected by changing var to out in FillChar parameter. I don't know by heart anymore, but as I mentioned

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Martin
Alexander Klenin wrote: On Thu, Nov 19, 2009 at 20:46, Jonas Maebe jonas.ma...@elis.ugent.be wrote: On 19 Nov 2009, at 11:42, Alexander Klenin wrote No, I asked for an example of code that would be negatively affected by changing var to out in FillChar parameter. I don't know by

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Jonas Maebe
On 19 Nov 2009, at 11:51, Alexander Klenin wrote: On Thu, Nov 19, 2009 at 20:46, Jonas Maebe jonas.ma...@elis.ugent.be wrote: I don't know by heart anymore, but as I mentioned the compiler crashed when I tried that (or if you did that move, which has the same problem). There is probably

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Alexander Klenin
On Thu, Nov 19, 2009 at 21:02, Jonas Maebe jonas.ma...@elis.ugent.be wrote: Ok, so how about introducing, say, FillMem procedure, which is identical to FillChar except that it has out parameter, See http://lists.freepascal.org/lists/fpc-devel/2009-November/018559.html FillMem would be a

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Vinzent Höfler
Florian Klaempfl flor...@freepascal.org: Without COM, FPC wouldn't have out parameters. And because there would be no difference between var and out then, it also wouldn't have the hint. Case dismissed. ;) Vinzent. -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Thaddy
Without COM, FPC wouldn't have out parameters. And because there would be no difference between var and out then, it also wouldn't have the hint. Case dismissed. ;) Vinzent. Yup. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Vinzent Höfler
Florian Klaempfl flor...@freepascal.org: A VAROUT parameter could have the same semantics as VAR except that the compiler does not expect that it is needed that it is initialized. But be warned: with such a parameter type you can easily create memory leaks with automated types like

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Florian Klaempfl
Vinzent Höfler schrieb: Florian Klaempfl flor...@freepascal.org: A VAROUT parameter could have the same semantics as VAR except that the compiler does not expect that it is needed that it is initialized. But be warned: with such a parameter type you can easily create memory leaks with

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Vinzent Höfler
Graeme Geldenhuys gra...@mastermaths.co.za: Can't the compiler simply initialize structured types by default? [...] After all, this is already done for AnsString, Integer type, real types etc... No, it's not (except for AnsiString, because it's reference counted). Vinzent. -- GRATIS für

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Vinzent Höfler
Florian Klaempfl flor...@freepascal.org: Vinzent Höfler schrieb: Florian Klaempfl flor...@freepascal.org: A VAROUT parameter could have the same semantics as VAR except that the compiler does not expect that it is needed that it is initialized. But be warned: with such a parameter

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Florian Klaempfl
Vinzent Höfler schrieb: Florian Klaempfl flor...@freepascal.org: Vinzent Höfler schrieb: Florian Klaempfl flor...@freepascal.org: A VAROUT parameter could have the same semantics as VAR except that the compiler does not expect that it is needed that it is initialized. But be warned: with

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Jonas Maebe
On 19 Nov 2009, at 22:31, Florian Klaempfl wrote: Because a VAROUT parameter would be simply overwritten by the callee even if it contains a valid automated type: procedure p(varout v : ansistring); begin v:='asdf'; end; I don't think that this could cause a memory leak, otherwise this

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Vinzent Höfler
Florian Klaempfl flor...@freepascal.org: Because a VAROUT parameter would be simply overwritten by the callee even if it contains a valid automated type: That's a semantic definition, not an explanation. IOW: What stops you from selecting to implement the proper semantics depending on the

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Florian Klaempfl
Vinzent Höfler schrieb: Florian Klaempfl flor...@freepascal.org: Because a VAROUT parameter would be simply overwritten by the callee even if it contains a valid automated type: That's a semantic definition, not an explanation. Sorry, but it seems you didn't follow up the thread, so I

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-19 Thread Vinzent Höfler
Florian Klaempfl flor...@freepascal.org: Vinzent Höfler schrieb: Florian Klaempfl flor...@freepascal.org: Because a VAROUT parameter would be simply overwritten by the callee even if it contains a valid automated type: That's a semantic definition, not an explanation. Sorry, but

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-18 Thread Graeme Geldenhuys
Jonas Maebe wrote: Delphi compatibility. And Delphi does that because COM requires this behaviour. Can't that behaviour be limited to Windows platform only. Now *all* platforms and all non-COM code has to be stuck with the useless compiler hint simply because of some Windows and more

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-18 Thread Florian Klaempfl
Graeme Geldenhuys schrieb: Jonas Maebe wrote: Delphi compatibility. And Delphi does that because COM requires this behaviour. Can't that behaviour be limited to Windows platform only. Now *all* platforms and all non-COM code has to be stuck with the useless compiler hint simply because

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-18 Thread Graeme Geldenhuys
Florian Klaempfl wrote: Without COM, FPC wouldn't have out parameters. Why do you say that? I see many use-cases for out parameters - all without using Windows or Windows+COM. Not to mention, even Kylix (which for obvious reasons doesn't have COM support) had out parameter support. So even

[fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-17 Thread Graeme Geldenhuys
Hi, I asked a question about a compiler hint in the fpc-users mailing list. As JoshyFun suggested, is it not maybe better to change FillChar() definition so first parameter is a out parameter - to prevent unnecessary compiler hint in code? Original Message Subject: Re:

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-17 Thread Jonas Maebe
On 17 Nov 2009, at 12:04, Graeme Geldenhuys wrote: I asked a question about a compiler hint in the fpc-users mailing list. As JoshyFun suggested, is it not maybe better to change FillChar() definition so first parameter is a out parameter - to prevent unnecessary compiler hint in code? No,

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-17 Thread Thaddy
Jonas Maebe wrote: On 17 Nov 2009, at 12:04, Graeme Geldenhuys wrote: I asked a question about a compiler hint in the fpc-users mailing list. As JoshyFun suggested, is it not maybe better to change FillChar() definition so first parameter is a out parameter - to prevent unnecessary compiler

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-17 Thread Jonas Maebe
On 17 Nov 2009, at 13:43, Thaddy tha...@thaddy.com wrote: Jonas Maebe wrote: No, that is not possible. I once tried to change move and fillchar to use out parameters instead of var parameters, and the result was all sorts of crashes. The reason is that out has special semantics for

Re: [fpc-devel] Redefine FillChar() to use out parameter instead

2009-11-17 Thread Thaddy
Jonas Maebe wrote: Delphi compatibility. And Delphi does that because COM requires this behaviour. Yes, but.. As I hinted before that is because COM is reference counted on an intermediate level by a certain OS. A simple (but performance cost) change of the memorymanager can fix that for