Re: [fpc-pascal] readonly variables
On 02 Dec 2009, at 10:26, Holger Bruns wrote: I checked this out. Both Turbo Pascal and fpc reported the same error massage: Variable identifier expected. You simply cannot pass constant values by reference. Passing a parameter by reference and "var" parameters are not the same thing. Const parameters are sometimes passed by reference, and sometimes not. Which it is depends on the implementation in the compiler and/or on the calling convention. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Anthony Walter schrieb: This first time concerning the topic "const records passed incorrectly" you said, "It is nowhere written in the Delphi specs that const parameters are passed by reference. It is often so, but is by no means guaranteed" I checked this out. Both Turbo Pascal and fpc reported the same error massage: Variable identifier expected. You simply cannot pass constant values by reference. HTH, Holger ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Sun, Nov 29, 2009 at 1:11 PM, Jonas Maebe wrote: > > On 29 Nov 2009, at 16:51, Anthony Walter wrote: > >> Having said all that, Jonas, what is the actual implemented behaviour >> of FPC? Does it 0 initialize heap memory at startup or not? > > I guess you mean global data rather than heap (heap is what is handled by > getmem/freemem/..., and there are no guarantees regarding that memory). > > FPC currently initialises the global data to 0 on platforms that do not do > this by themselves. When it turns global variables into register variables, > it will also initialise such registers with 0. > >> If not, >> what is the justification for not doing so when this has been a long >> established behaviour of Delphi? > > A justification could be that it causes code bloat in case of register > variables, and that platforms which do not zero global data memory by > themselves are usually embedded devices where every operation counts (both in > terms of code size and in terms of energy usage). > > > Jonas___ FWIW, IIRC the last time this issue (global variables initialization) came up some FPC developer explained this was a platform specific behavior and shouldn't be counted on, so I thought MvC was right in this thread up to now... -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
In our previous episode, Jonas Maebe said: > >> anything to say on the subject is patently false. > > > > As per what? OS ABI? Delphi rules? > > As per the linked Delphi documentation. But as has mentioned before, the > Delphi documentation doesn't match its implementation in case of cdecl and > const records (of course, this sort of things never happen with FPC :). > Can we close this topic now? Sure, sorry was working away a backlog and hadn't seen the newer ones yet. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On 30 Nov 2009, at 10:29, Marco van de Voort wrote: > In our previous episode, Anthony Walter said: >> Martin Schreiber also chimed in, pointing out: >> >> http://bit.ly/6uaAiB >> >> "Larger sets, records, and static arrays are passed as 32-bit pointers >> to the value." >> >> The documentation is unambiguous there. Claiming that it doesn't have >> anything to say on the subject is patently false. > > As per what? OS ABI? Delphi rules? As per the linked Delphi documentation. But as has mentioned before, the Delphi documentation doesn't match its implementation in case of cdecl and const records (of course, this sort of things never happen with FPC :). Can we close this topic now? Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
In our previous episode, Anthony Walter said: > > "Allows" is not the same as "forces". This line in the help file does not > > say that const parameters are passed by reference. It says that it may often > > be so, perhaps all current implementations make it so, but it is by no means > > guaranteed. > > Martin Schreiber also chimed in, pointing out: > > http://bit.ly/6uaAiB > > "Larger sets, records, and static arrays are passed as 32-bit pointers > to the value." > > The documentation is unambiguous there. Claiming that it doesn't have > anything to say on the subject is patently false. As per what? OS ABI? Delphi rules? That's the problem with relying on Delphi docs for these kinds of things, there is no difference made there what is implementation defined (e.g. x86isms, windows ABI isms like COM compatibility etc), and what not. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
This is quite simple : 1 - Imagine that fpc initializes all memory to 0. 2 - Imagine that you are running on a low power platform. 3 - You are not going to use the default value of 0. 4 - You reinitialize the memory to your own default value. See, you did TWO memory store instructions instead of just one, and this is a waste of time/power. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
> So it seems that passing them by value actually corresponds to what the > Delphi docs say. Jonas, I agree, the documentation definitely does address the issue, which was where that conversation was derailed. Regarding actual implementation, I previously posted the full source to a test program with the results. The conclusion was that Delphi and FPC work the same, except when the convention is changed to cdecl. Under cdecl FPC returns "R is a structure on the stack" and Delphi returns "R refers to a reference on the stack". If anyone wants to repeat the tests, the source code is located under the link you last provided. Just change the calling convention of function A to see how the compiler handles parameters differently. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On 29 Nov 2009, at 22:59, Anthony Walter wrote: >> Do you mean this one? >> >> "Using const allows the compiler to optimize code for structured- and >> string-type parameters." >> >> "Allows" is not the same as "forces". This line in the help file does not >> say that const parameters are passed by reference. It says that it may often >> be so, perhaps all current implementations make it so, but it is by no means >> guaranteed. > > Martin Schreiber also chimed in, pointing out: > > http://bit.ly/6uaAiB > > "Larger sets, records, and static arrays are passed as 32-bit pointers > to the value." I believe that the previous thread that's referred to above was about cdecl functions: http://lists.freepascal.org/lists/fpc-pascal/2009-November/023125.html And the documentation you linked goes on to say: "[Larger sets, records, and static arrays are passed as 32-bit pointers to the value.] An exception to this rule is that records are always passed directly on the stack under the cdecl, stdcall, and safecall conventions; the size of a record passed this way is rounded upward to the nearest double-word boundary." So it seems that passing them by value actually corresponds to what the Delphi docs say. Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
> Do you mean this one? > > "Using const allows the compiler to optimize code for structured- and > string-type parameters." > > "Allows" is not the same as "forces". This line in the help file does not > say that const parameters are passed by reference. It says that it may often > be so, perhaps all current implementations make it so, but it is by no means > guaranteed. Martin Schreiber also chimed in, pointing out: http://bit.ly/6uaAiB "Larger sets, records, and static arrays are passed as 32-bit pointers to the value." The documentation is unambiguous there. Claiming that it doesn't have anything to say on the subject is patently false. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Anthony Walter wrote: Okay, I am going to call bullshit on you. This is the second time (in a few weeks) where you've replied to something I've written with wrong information. This first time concerning the topic "const records passed incorrectly" you said, "It is nowhere written in the Delphi specs that const parameters are passed by reference. It is often so, but is by no means guaranteed" That time I corrected you by pointing out the line in the help file contradicting your assertion. Do you mean this one? "Using const allows the compiler to optimize code for structured- and string-type parameters." "Allows" is not the same as "forces". This line in the help file does not say that const parameters are passed by reference. It says that it may often be so, perhaps all current implementations make it so, but it is by no means guaranteed. Frank ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Nov 28, 2009, at 1:15 PM, Anthony Walter wrote: This is not guaranteed in any way. It happens to be so most of the time, but your code should never assume this is so, except for global Ansistring variables. If all globals weren't initialized to 0 a lot of code from lots of people would potentially be in trouble. I've been using Pascal/Delphi for a very long time. Trust me I know my stuff. For what its Wirth None of our code ass-u-me-s (nor requires) initialization of _our_ globals (or locals) by any compiler or OS; all of our globals and locals are specifically initialized. Helps us survive the shifting Macintosh pascal compiler scene with 1988 source code. Before that I used Pascal at Honeywell, 1978-1988; all variables were initialized by their programs, not the OS, not the compiler. Gary ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Jonas Maebe wrote: On 29 Nov 2009, at 19:20, Mehmet Erol Sanliturk wrote: My experience with Windows XP Professional is that it is NOT zeroing the memory . I know this from actual Delphi ( and also Free Pascal ) compiled program executions . Due to this I am explicitly initializing all of the local simple variables , elements of records . The discussion was about global variables, not about local variables. Local variables are indeed not initialised (not in FPC nor in Delphi/TP). Jonas Dear Jonas , I am sorry about my misunderstanding . We may think the global variables are placed in memory which is not cleaned by operating system before starting the program . Therefore it is necessary to initialize them . In a FreeBSD mailing list thread this point is discussed about security vulnerability by complaining about a package that it was not cleaning its global/local variables before terminating and leaving values of them in memory ( this shows that FreeBSD is NOT clearing memory itself running that package ) . My habit is nearly in all of my programming life ( even in BASIC ) to initialize all of the variables by myself . Now , I am removing almost ALL of the global variables by making them local to starting procedures . If I can not do that , nearly ALL of my global variables are placed into RECORD declarations to prevent accidental effects of local variable declarations with the same name hiding the global variable ( therefore causing nearly impossible to find bugs ) . This shows reason of my misunderstanding because for me there is no such an initialization by compilers concept . Thank you very much . Mehmet Erol Sanliturk ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Sun, Nov 29, 2009 at 1:59 PM, Jonas Maebe wrote: > > On 29 Nov 2009, at 19:20, Mehmet Erol Sanliturk wrote: > > > My experience with Windows XP Professional is that it is NOT zeroing the > memory . I know this from actual Delphi ( and also Free Pascal ) compiled > program executions . Due to this I am explicitly initializing all of the > local simple variables , elements of records . > > The discussion was about global variables, not about local variables. Local > variables are indeed not initialised (not in FPC nor in Delphi/TP). > Yes, as Jonas said we were discussing global variables which are indeed initialized to 0 (according to what Jonas has said). This is a documented behaviour. As an aside, this behavior also extends to class fields upon instantiation. Conversely, local variables are not initialized. This is because locals are references to memory on the stack and are reused as offsets from the stack pointer register. This mean that you must initialize local variables before using them or you may encounter unexpected results. As far as I can recall this is the way things have always been. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On 29 Nov 2009, at 19:20, Mehmet Erol Sanliturk wrote: > My experience with Windows XP Professional is that it is NOT zeroing the > memory . I know this from actual Delphi ( and also Free Pascal ) compiled > program executions . Due to this I am explicitly initializing all of the > local simple variables , elements of records . The discussion was about global variables, not about local variables. Local variables are indeed not initialised (not in FPC nor in Delphi/TP). Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Micha Nelissen wrote: Anthony Walter wrote: Having said all that, Jonas, what is the actual implemented behaviour of FPC? Does it 0 initialize heap memory at startup or not? If not, what is the justification for not doing so when this has been a long established behaviour of Delphi? It's not the compiler or RTL that zeroes the memory, but the OS. Therefore, it cannot be guaranteed by the fpc documentation (except if it would contain code to explicitly initialise that memory). Most OSes (Windows, Linux, BSDs, ...) do zero global memory though, to prevent leakage of (potentially security sensitive) information from one process to another. Micha My experience with Windows XP Professional is that it is NOT zeroing the memory . I know this from actual Delphi ( and also Free Pascal ) compiled program executions . Due to this I am explicitly initializing all of the local simple variables , elements of records . To rely on behaviors of operating systems or compilers in that subject may produce very unreliable programs because these tools ( compilers and operating systems ) may be modified in unexpected ways . Therefore best action is to initialize the variables explicitly which is the most reliable way to maintain robustness of developed programs . Thank you very much . Mehmet Erol Sanliturk ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Sun, 29 Nov 2009, Anthony Walter wrote: Jonas, Thank you. I certainly will make an attempt to tone down a few of my remarks which I admit were inflammatory. I assure everyone here though, my purpose in conversing on these lists is to help improve FPC, so far by discussing easy to resolve and reproduce technical points. I personally find it quite irksome to when someone repeatedly interrupts a discussion by injecting false information. Especially so when they continue despite being presented with easily verified facts. My poor manners put aside for the moment, if someone states ~this is nowhere in documentation~ and is then fact checked showing the opposite, I expect to hear back from him with an "oh yes, you are correct. the documentation does contain that information". If we're dealing with verifiable facts, let us look at my mail. I quote: -- I believe that. I know it is so in practice, but nowhere it says in the Pascal language specification that this is guaranteed by the compiler. -- The FPC (or Delphi) documentation is not the same as the Pascal Language specificiation. The Pascal language specification is an ISO document, freely available. I was referring to the latter. In fact, the Pascal language specs explicitly state that the initial state of a variable is undefined unless an initial value is specified; I just re-checked that, please see http://standardpascal.org/iso10206.pdf (be warned, it is not easy reading...) So next time, before you get angry, please reconsider: There may be some - entirely unintentional - confusion in used terminology. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
> > FPC currently initialises the global data to 0 on platforms that do not do > this by themselves. When it turns global variables into register variables, > it will also initialise such registers with 0. > Ah, okay. So it is working as expected. Thanks for the reply. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On 29 Nov 2009, at 16:51, Anthony Walter wrote: > Having said all that, Jonas, what is the actual implemented behaviour > of FPC? Does it 0 initialize heap memory at startup or not? I guess you mean global data rather than heap (heap is what is handled by getmem/freemem/..., and there are no guarantees regarding that memory). FPC currently initialises the global data to 0 on platforms that do not do this by themselves. When it turns global variables into register variables, it will also initialise such registers with 0. > If not, > what is the justification for not doing so when this has been a long > established behaviour of Delphi? A justification could be that it causes code bloat in case of register variables, and that platforms which do not zero global data memory by themselves are usually embedded devices where every operation counts (both in terms of code size and in terms of energy usage). Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Anthony Walter wrote: Having said all that, Jonas, what is the actual implemented behaviour of FPC? Does it 0 initialize heap memory at startup or not? If not, what is the justification for not doing so when this has been a long established behaviour of Delphi? It's not the compiler or RTL that zeroes the memory, but the OS. Therefore, it cannot be guaranteed by the fpc documentation (except if it would contain code to explicitly initialise that memory). Most OSes (Windows, Linux, BSDs, ...) do zero global memory though, to prevent leakage of (potentially security sensitive) information from one process to another. Micha ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Jonas, Thank you. I certainly will make an attempt to tone down a few of my remarks which I admit were inflammatory. I assure everyone here though, my purpose in conversing on these lists is to help improve FPC, so far by discussing easy to resolve and reproduce technical points. I personally find it quite irksome to when someone repeatedly interrupts a discussion by injecting false information. Especially so when they continue despite being presented with easily verified facts. My poor manners put aside for the moment, if someone states ~this is nowhere in documentation~ and is then fact checked showing the opposite, I expect to hear back from him with an "oh yes, you are correct. the documentation does contain that information". After that we could move on to other topics such as is this behaviour correct, shall we revise to documentation, what impact will changing the behaviour have on developers? Now putting my bad manners on the table, I admit to quickly escalated a situation, with little to no established rapport, but I was also correct in my facts. Having said all that, Jonas, what is the actual implemented behaviour of FPC? Does it 0 initialize heap memory at startup or not? If not, what is the justification for not doing so when this has been a long established behaviour of Delphi? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On 28 Nov 2009, at 23:31, Anthony Walter wrote: > This second time regarding the current discussion you said: "This is > not guaranteed in any way." and "nowhere it says in the Pascal > language specification that this is guaranteed by the compiler" > > And I responded with the section, subsection, page number, and direct > quote contradicting your assertion. The FPC documentation is not the same as the Pascal language specification, although it is obviously the intention that it does accurately describe FPC's implementation. Just like the code, the documentation can also contain bugs though. You're right that Michael's first statement was wrong, but do believe me when I say that he is not the kind of person that has a problem with admitting that he's wrong when he is (I personally have a lot more trouble with doing that from time to time, fwiw). I can assure you that he was not making things up when he explained his reasoning, so yes, he probably just forgot that this was written in our docs. That said, I would like to ask you to be less aggressive. Such a tone is unlikely to result in productive results for anyone. Jonas FPC mailing lists admin___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Hi Jürgen, > Not that I am aware of. But for what reason do you want such a behaviour? I wrote data analysis programs which are very difficult. I change some lines to optimize a program. Somethimes it is necessary that I will save a variable after an input because the second setup of the variable is an error the first is ok. If I use the bash I can save the variables after an initialisation with the "readonly" command. At this time it is not possible to reset the variable. This is very helpfull, because you can avoid an anlysis error by forcing a program runtime error. Thanks, Markus ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On 28 Nov 2009, at 22:34, Michael Van Canneyt wrote: > It was Jonas Maebe (Jonas, correct me if I'm wrong) who pointed > out (already some time ago) that this behaviour is purely coincidental (but > admittedly convenient), and should not be taken for granted. That's correct, Usually, this is brought up in the context of the warning Variable "yyy" does not seem to be initialized in reference to a global variable. The argument is that this warning is wrong in that context, since it is actually initialised (with 0). While the answer that this is not guaranteed is correct in theory (as in "in terms of what the Pascal standard mandates"), the fact that TP and Delphi do guarantee this and that many people rely on this behaviour probably means that we will also always guarantee it. Maybe we should simply reword the warning to read Variable "yyy" may be read before it is written or something similar (although that's not directly relevant to this discussion). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Anthony Walter wrote: Okay, I am going to call bullshit on you. I, like many others in this list, resent your unwarranted behavior towards Michael Van Canneyt. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Florian Klaempfl wrote: Anthony Walter schrieb: Okay, I am going to call bullshit on you. What about just unsubscribing from the list? Nobody needs you here. MvC did an incredible job on FPC docs, you just waste our time. Actually it is a very ridiculous behavior to talk about developers of the Free Pascal and Lazarus by using such words . To hear such an ugly sentence is a very disgusting experience . Ideas may be different from the Free Pascal or Lazarus developers , but expressing such ideas do not give any one to right to use any meaningless and useless expressions . No one should forget that Free Pascal and Lazarus developers are consuming a portion of their lives for benefits of us , and they only deserve a great thank you to themselves . I am writing programs since 1970 and I know many programming languages . Pascal is still the one of the most elegant languages . The tasks of developers of Free Pascal and Lazarus are not easy ones . Instead of blaming them , it is necessary to help them by writing test programs , feature implementation samples tested very well and accompanied with test programs and documentation , documentation of parts which can be used for teaching of these parts , bug reports containing sufficiently expressive how to fixes may be developed and others . Thank you very much . Mehmet Erol Sanliturk ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Anthony Walter schrieb: > Okay, I am going to call bullshit on you. What about just unsubscribing from the list? Nobody needs you here. MvC did an incredible job on FPC docs, you just waste our time. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Can we please not start bashing people here? (Cuuntry of origin: Netherlands, so not a native English speaker as well) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Anthony Walter schrieb: I don't care if you claim to have written documentation, you clearly either don't have a grasp of the English language, good memory, research skills, or some combination those deficiencies. Michael and so Jonas are Authors and Developers of FPC. Most FPC Authors are from Europe and english is not their first language... -Ivo Steinmann (Swiss, just to mention that english isn't my first language either) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Michael - I see you are one of the authors of fpc (thank you), so I assume your statement is true by virtue of "inside knowledge". But this is a concern. As I'm sure you will know, in Delphi globals are always initialised to zero - and in my experience (almost 15 years with a 30-strong Delphi developer team) it is universally relied upon. Is this a case where FPC does not conform to Delphi behaviour? If not, why not? It would seem simple enough to ensure the global space in the heap is zeroed at allocation - or even that the compiler initialised each individually by "assuming" " = 0", " = nil", etc at the end of a global declaration if nothing else has been specified. Regards, Andrew Hall. On 28 Nov 09, at 11:58 , Michael Van Canneyt wrote: >> Global variables (even in the implementation section) are always >> initialized to 0. > > This is not guaranteed in any way. It happens to be so most of the time, > but your code should never assume this is so, except for global Ansistring > variables. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
Okay, I am going to call bullshit on you. This is the second time (in a few weeks) where you've replied to something I've written with wrong information. This first time concerning the topic "const records passed incorrectly" you said, "It is nowhere written in the Delphi specs that const parameters are passed by reference. It is often so, but is by no means guaranteed" That time I corrected you by pointing out the line in the help file contradicting your assertion. Martin Schreiber also chimed in, pointing out you were plainly wrong. In case you forgot, here is a refresher: http://tinyurl.com/yz8pqfv This second time regarding the current discussion you said: "This is not guaranteed in any way." and "nowhere it says in the Pascal language specification that this is guaranteed by the compiler" And I responded with the section, subsection, page number, and direct quote contradicting your assertion. I don't care if you claim to have written documentation, you clearly either don't have a grasp of the English language, good memory, research skills, or some combination those deficiencies. When we (English speakers) say "nowhere", it means "a state of nonexistence" or "not anywhere". When I, and others, then find the exact lines of said documentation proving your assertions that nothing of the sort was in the documentation, then you are wrong, and now doubly so. You have lost credibility IMO, and I foresee a trend where you are digging yourself further into a hole. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Sat, 28 Nov 2009, Anthony Walter wrote: That should be removed, actually. I'll take that as an admission that you were wrong. It's in the specification, lot's of code uses the feature, and it works the way I described. I'm not admitting anything here, I am attempting to enlighten you :-) Changing the specification to match your argument is stupid. I'm not changing any specifications. They are what they are, I neither make nor control them. I did create the docs, and at that time I believed that the zero-out behaviour of the compiler/linker for certain sections in the executable could be taken for granted. It was Jonas Maebe (Jonas, correct me if I'm wrong) who pointed out (already some time ago) that this behaviour is purely coincidental (but admittedly convenient), and should not be taken for granted. At that time I should have removed the statement you refer to from the docs, but I did not (I probably forgot it was there in the first place). So: no "admissions", just a lesson in history of FPC and its docs. I'll now confer with the rest of the Core team about our 'official' attitude in this. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
> That should be removed, actually. I'll take that as an admission that you were wrong. It's in the specification, lot's of code uses the feature, and it works the way I described. Changing the specification to match your argument is stupid. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Sat, 28 Nov 2009, Anthony Walter wrote: This is not guaranteed in any way. It happens to be so most of the time, but your code should never assume this is so, except for global Ansistring variables. If all globals weren't initialized to 0 a lot of code from lots of people would potentially be in trouble. I've been using Pascal/Delphi for a very long time. Trust me I know my stuff. I believe that. I know it is so in practice, but nowhere it says in the Pascal language specification that this is guaranteed by the compiler. From the language specification: Section: Data Types, Variables, and Constants Sub-section: Declaring Variables Page: 102 "If you don't explicitly initialize a global variable, the compiler initializes it to 0." That should be removed, actually. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
> This is not guaranteed in any way. It happens to be so most of the time, > but your code should never assume this is so, except for global Ansistring > variables. If all globals weren't initialized to 0 a lot of code from lots of people would potentially be in trouble. I've been using Pascal/Delphi for a very long time. Trust me I know my stuff. >From the language specification: Section: Data Types, Variables, and Constants Sub-section: Declaring Variables Page: 102 "If you don't explicitly initialize a global variable, the compiler initializes it to 0." ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Sat, 28 Nov 2009, Anthony Walter wrote: PrivateMyVariableSet is not intialised, so will have an undefined (random) value when InitMyVariable is first called. Mattias' code given earlier avoids this problem. Bzzzt. Wrong. Global variables (even in the implementation section) are always initialized to 0. This is not guaranteed in any way. It happens to be so most of the time, but your code should never assume this is so, except for global Ansistring variables. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
> PrivateMyVariableSet is not intialised, so will have an undefined > (random) value when InitMyVariable is first called. > Mattias' code given earlier avoids this problem. Bzzzt. Wrong. Global variables (even in the implementation section) are always initialized to 0. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Sat, 28 Nov 2009 12:10:48 -0500 Anthony Walter wrote: > procedure InitMyVariable(Value: T); > function MyVariable: T; > > implementation > > var > PrivateMyVariable: T; > PrivateMyVariableSet: Boolean; > > procedure InitMyVariable(Value: T); > begin > if not PrivateMyVariableSet then > PrivateMyVariable := Value; > PrivateMyVariableSet := True; > end; > > function MyVariable: T; > begin > Result := PrivateMyVariable; > end; PrivateMyVariableSet is not intialised, so will have an undefined (random) value when InitMyVariable is first called. Mattias' code given earlier avoids this problem. Howard ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
procedure InitMyVariable(Value: T); function MyVariable: T; implementation var PrivateMyVariable: T; PrivateMyVariableSet: Boolean; procedure InitMyVariable(Value: T); begin if not PrivateMyVariableSet then PrivateMyVariable := Value; PrivateMyVariableSet := True; end; function MyVariable: T; begin Result := PrivateMyVariable; end; ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
You can use read function: var DirectAccessToValue: T; function Value: T; inline; begin Result := DirectAccessToValue; end; begin ... DirectAccessToValue := ...; ... DoSomething(Value); end. On Sat, Nov 28, 2009 at 13:55, Markus Glugla wrote: > Hello, > > is it possible to set a variable in a programm as a readonly variable? > > I would set a variable at a position in the runing programm. Since this > time the variable should be readonly. The next set of the variable > should produce an error. > > In bash programming you found a command "readonly" making this effect. > Is there a command for FreePascal? > > Thanks, > Markus > > program readonly; > ... > v:=1; // At this position it should be readonly. > ... > end. > > > > > ___ > fpc-pascal maillist - fpc-pas...@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > -- Aleksa Todorovic - Lead Programmer Eipix Entertainment http://www.eipix.com/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Sat, 28 Nov 2009 15:07:42 +0100 Mattias Gaertner wrote: > On Sat, 28 Nov 2009 14:58:26 +0100 > Jürgen Hestermann wrote: > > > > is it possible to set a variable in a programm as a readonly variable? > Use the following: > > property MyVar: integer read FMyVar write SetMyVar; > > And in SetMyVar you can set flag and raise an exception if set for the > second time. If the value is known in advance and if no runtime alteration of the variable is allowed you would of course declare the value as const rather than var. But this may not fit your case? Howard ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Sat, 28 Nov 2009 14:58:26 +0100 Jürgen Hestermann wrote: > > is it possible to set a variable in a programm as a readonly variable? > > Not that I am aware of. But for what reason do you want such a behaviour? > > And if I think it over, this can only work at runtime (letting the program > crash on the second assignment). At compile time the compiler may not exactly > know which assignment is done in what order. If you set the variable in a > procedure or function the compiler would have to check when this procedure is > called (which can be called by another procedure and so on). The first call > (and assignment) would be ok but the second should generate an error? How > should the compiler know how often the routine is called? This can even be > dependend on input data. Same under bash. Use the following: property MyVar: integer read FMyVar write SetMyVar; And in SetMyVar you can set flag and raise an exception if set for the second time. Mattias ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
is it possible to set a variable in a programm as a readonly variable? Not that I am aware of. But for what reason do you want such a behaviour? And if I think it over, this can only work at runtime (letting the program crash on the second assignment). At compile time the compiler may not exactly know which assignment is done in what order. If you set the variable in a procedure or function the compiler would have to check when this procedure is called (which can be called by another procedure and so on). The first call (and assignment) would be ok but the second should generate an error? How should the compiler know how often the routine is called? This can even be dependend on input data. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] readonly variables
Hello, is it possible to set a variable in a programm as a readonly variable? I would set a variable at a position in the runing programm. Since this time the variable should be readonly. The next set of the variable should produce an error. In bash programming you found a command "readonly" making this effect. Is there a command for FreePascal? Thanks, Markus program readonly; ... v:=1; // At this position it should be readonly. ... end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal