'?' operator for pointer bounds and null check
Posted: Wed Jul 01, 2009 5:15 am
Consider this example:
There is no guarantee that an acceptable type is being passed using a simple pointer. This functionality can sometimes be desired. However it would be nice to be able to do bounds and null checking automatically to prevent errors and also to simplify code.
It is currently possible to check for a null pointer but this check is so common that it would be a benefit to have the functionality built in.
My suggestion is:
This feature would require labels to be considered out of scope for the function when its prototype specifies a parameter with the same name.
These ideas are taken from Cyclone's concept of the safe pointers:
http://en.wikipedia.org/wiki/Cyclone_(p ... _language)
Code: Select all
Procedure This(*That.Quad)
;/ We can check for a null pointer but not for an out of bounds exception
If Not *That
ProcedureReturn
EndIf
Debug *That\q ;/ Null pointer causes runtime error here
EndProcedure
Define N.q=9223372036854775807
Define Q.b
This(@N) ;/ Ok!
This(@Q) ;/ Many crash/may not crash
This(0) ;/ Runtime error only if procedure attempts to access it
It is currently possible to check for a null pointer but this check is so common that it would be a benefit to have the functionality built in.
My suggestion is:
Code: Select all
;/ Automatic bounds and null check using '?*' in place of '*' for parameter lists
Procedure This(?*That.Quad)
Debug *That\q
EndProcedure
Define N.q=9223372036854775807
Define Q.b
This(@N) ;/ Ok!
This(@Q) ;/ Compiler error here!
This(0) ;/ Runtime error here!
These ideas are taken from Cyclone's concept of the safe pointers:
http://en.wikipedia.org/wiki/Cyclone_(p ... _language)