1. A constant Number does not have an Datatype! It can be assigned to any variable. Why do you think that the constant #ConstL=12345678 is a long?
2. I am not sure, if constant numbers are stored somewhere in an internal data section like strings. I think this is not the case.
Try this code to test this:
Code: Select all
Prototype ptPassLongPointer(Long.L)
Procedure GetConstantAddress(*ConstantL)
ProcedureReturn *ConstantL
EndProcedure
#ConstL=12345678
#Const2=23456789
AddrOfL.ptPassLongPointer=@GetConstantAddress()
PTRL=AddrOfl(#ConstL)
Debug "Long Constant Ptr "+Str(@PTRL) ;OK
Debug PeekL(@PTRL)
PTRL=AddrOfl(#Const2)
Debug "Long Constant Ptr "+Str(@PTRL) ;OK
Debug PeekL(@PTRL)
Both constants #ConstL and #Const2 would have the same address! This can not be right!
There is a mistake in your code! Not the pointer of the variable is passed to the function, but the value! Try this code:
Code: Select all
Prototype ptPassLongPointer(Integer)
Procedure GetConstantAddress(ConstantL)
Debug ConstantL
ProcedureReturn ConstantL
EndProcedure
#ConstL=12345678
#Const2=23456789
AddrOfL.ptPassLongPointer=@GetConstantAddress()
Debug AddrOfl(#ConstL)
Debug ""
Debug AddrOfl(#Const2)
==> In your code you assign the value of the constant to PTRL (which is an integer variable)! ... the value is returned by the function!
==> With Debug Str(@PTRL) the pointer to the variable PTRL is shown!
==> With PeekL(@PTRL) you get the value of the PTRL variable!
This cannot be used to get the pointer of numerical constants, because (1) the value is passed to function (not the pointer) ... and because (2) numerical constants are never stored in an internal datasection (like strings).
3. For strings it is working as long the behavior of Pseudotypes is not changed! If the string, which is passed to the function, has the same string format (the same pseudotype) as the argument, the pointer to the original string is passed to the function.
If the formats are different the string is converted to the other format (given by the pseudotype). And the pointer to this temporary string is passed to the function ... and is only valid for the function itself.
As long PureBasic does pass the pointer to the original string, if the formats are the same, this "workaround" works. But if this behaviour is changed in the future, this will not work anymore!
The pseudotypes are designed to tell the compiler how to pass strings (and also variants) ... and (if necessary) do a conversion of the data.
cu, helpy