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
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.
Quad is a Structure, q is a Type.
you can structure a pointer using Quad, to be able to access the .q type behind it,
but you cannot type a pointer, it would just make the pointer 64bit long, but not work the way you want it.
Quad is a structure that contains one member of type .q. They are not of the same type. One is a structure and the other is an intrinsic type. It's like comparing apples and orange paint. So in this case, the feature would be useless, as you're passing the address of a variable of type .q while the procedure expects the address of a variable of type .quad. So you will get a compile time type error.
I think you're misunderstanding my request. I specifically said "bounds check" and not "type check". Both .Quad and .q are the same size. Requiring strict type checking here wouldn't work.
PureBasic doesn't provide facilities like C does for casting as part of an expression and pointers aren't as powerful. Because the pointer types are not as flexible it would have to be bounds checking instead of type checking. Everything in PureBasic is a void* pointer.
It's not a void* pointer as you can associate a structure to it. Now, there is no type check when assigning a value to a pointer, which is not a big limitation IMHO.
Mistrel wrote:I think you're misunderstanding my request. I specifically said "bounds check" and not "type check". Both .Quad and .q are the same size. Requiring strict type checking here wouldn't work.
And what would be the purpose of such a bound check that doesn't check the type? It would be useless, since the parameter could expect a structure with a string variable (or any pointer), but get one of equal size, where the equivalent structure field was not a pointer (or a pointer of the wrong type).
Then you would end up with an invalid memory access even thought you thought you were safe due to the bounds check and be more confused than ever.