|
Rory Hewitt wrote:
... Hence, it's ALWAYS a good idea to use the N extender to the DEALLOC op-code. That way, you'll pick up any of these errors in testing, because your program will throw an error. Frankly I don't know why IBM didn't make the N-extender the default - backwards-compatibility, I assume.
Backwards compatibility wasn't an issue when DEALLOC was first invented. I agree that it's always a good idea to use (N). If I recall correctly (and I should, since this was my doing), the reason for not always setting the dealloc'd pointer to null was to try to force RPG programmers to be a conscious of the need for clearing the pointer after deallocation. If it was always just that one pointer variable that had the address of the allocated storage, there would be no issue, but a programmer should be aware of any other variables that should also be cleared. p = %alloc(len); save_p = p; ... p = p + offset; ... dealloc(n) save_p; // p is now pointing to illegal storage but the compiler has no way to know that // or rather, the compiler isn't nearly smart enough to know that I have seen dealloc(n) coded in many real RPG programs, so clearly some RPG programmers are conscious of it. I suspect the set of RPG programmers that codes (N) is the same set that would know to clear the pointer anyway. But maybe, just maybe, some other programmers have seen the (N) when reading or copying code, and have learned something from it. In hindsight, I think it would probably have been better just to always clear it, to take care of 99.9% of the opportunities for error.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.