A horrible bug....
Posted 16 July 2001 - 12:59 PM
Just thought I would let you know....
We found a horrible bug that actually lets you assign another value to a numeric literal.
If call a Global Function and pass a numeric literal to that function and the global function changes that parameter then once back in the calling function that literal remains changed.
For example, if function FUN1 calls Global LS function GFUN1 and passes the literal 1 in a parameter list and the global function GFUN1 modifies that parameter to 6 (Now I know that you should not do this, but due to human error this could occur, and does) then once back into FUN1, if you do a UMSG('Val:' CONV(1),-1) you get 6 output!!!!
This is the second time we have had this, and it has take the programmer quite alot of time to workout what was going on.
On a side note, It was quite useful to have access to the Bootstrap files so that we could write a function to find these 'problem' functions.... Something we may not have the privilege of doing in the future...
I would certainly not want to go through our 200 Global Functions manually every few weeks looking for this bug.
Posted 16 July 2001 - 02:00 PM
Use Developer Studio! This has a warning message in it to warn a programmer that they have made a coding error if they code a literal as a global function parameter that is either type B or O. Developer Studio also issues another warning if you try to gen a function with a literal passed as a parameter.
I'm sure that VIP will also have similar checks.
Posted 16 July 2001 - 02:32 PM
I'll have to argue about it not being a bug.... You should not be able to change the value of a literal. Period.
When would that be needed???
Sorry, going to DS is not really an option for us.
I really dont think that our customer would like the slow down with development due to the learning curve and the way DS works. They want to see new functionality in their system not a GUI development system. Going to DS has no value to us.
This would cost them alot of money as there are 25 developers in our team, and PRO-AIDE is the quickest development env. there is.
The other point I was trying to make was that there are times that we need to modify/search through the bootstrap files freely.....
Posted 16 July 2001 - 06:11 PM
'Y' and 'N':
create a global with a 'B' parameter that changes that parameter to 'N'
Call this global and pass it 'y' as a parameter...
for the rest of the calling function's logic,
IF 'Y' = 'N' will now be true...
Posted 17 July 2001 - 11:18 AM
'Due to a mixup between the numbers 5 and 7 NASA made a huge mistake earlier today. Ensign Gadsby who was chosen to eliminate the mad genious Captain Mellis on the 5th planet from the Sun actually landed on the 7th. NASA only realised the blunder after this transmission was received.
Houston: Gadsby, confirm you current position.
Gadsby : Houston, uhh current position unknown. I think I can see Jupiter out of the port window.
Houston: Ah, standby.
Gadsby : Roger, standby.
Houston: Ah, Gadsby we have your last transmission from Uranus.
Gadsby : Houston, we have a problem.
Houston: Standby....We have spoken to technical and they tell us although you are transmitting from Uranus it's Ok because 7 does in fact equal 5 and therefore Uranus is in fact Jupiter.
Gadsby : Thankyou Houston. It all makes sense now.'
Posted 17 July 2001 - 03:44 PM
I remember noticing this years ago using global logic (before global functions even existed). I expect it's still BAD there too - I wonder if DS spots that?
This is not an inherent 'feature' of languages that have call by reference. Most compilers end up placing constants in a separate memory segment to variables and a runtime error should arise if you try to write to the address of a constant (effectively in read-only memory)
Although C may may not have call-by-reference explicitly, it has for all practical purposes because it has pointers - you can simply pass the pointer as an argument.
One reason C has the const keyword is so issues like this can be made safe and explicit (a reference to a constant is not an lvalue and so on).
I'm with Rob - no self-respecting language should allow you to inadvertently change the value of a literal.
Posted 17 July 2001 - 04:39 PM
This IS a feature of pass by reference. In all (at least all that I know of) languages that allow literals to be passed by reference a copy of the literal has to be made in order to pass a reference to it.
>Although C may may not have call-by-reference explicitly, it has for all practical purposes because it has pointers - you can simply pass the pointer as an argument.
No. Pass by pointer is pass by value. You are passing the value of the pointer.
>One reason C has the const keyword is so issues like this can be made safe and explicit (a reference to a constant is not an lvalue and so on).
There are no references in C. In C plus plus (anyone know how to get a plus?) yes there are references and you have to have const references in order to pass a literal. This may involve calling of constructors and destructors and other unexpected effects.
However, changing the value of a literal is not even limited to pass by reference. In some versions of C it was possible to change the value of a constant string.
This is not a bug, and is even 'allowed' by the C standards because you are invoking undefined behaviour.
Posted 17 July 2001 - 04:41 PM
Reply to this topic
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users