06-18-2025, 05:51 PM
(This post was last modified: 06-18-2025, 05:59 PM by CookieOscar.)
Sorry to intersect... I was snooping around the forums for interesting stuff and came across your thread.
Is it correct that your question is actually "how to distinguish between a variable passed by reference vs. passed by value"? Because that is essentially what you're asking IMHO.
When you pass a literal string in normal BASICs, you actually pass a (internal) variable "by value".
This means changing its value inside the SUB has no reflection on the 'outside world'; there is no way to catch the change outside the sub. This in contrast to passing "by reference". Which means you actually pass a pointer to a variable. And as such, if you change the contents of the variable inside the SUB, the change WILL reflect outside the sub; the parameter variable has changed.
The big question I have is: *Why?* Why would you want to know that difference? I really can not think of a proper reason that you would want to know if it is a literal or not. ie. IF it was a literal, nothing would change anyways, so why bother?
I really would like to see this subroutine of yours to understand WHY it is needed/so important, if possible.
(well, TBH, the only reason I can think of is because of performance: If you pass a literal string to a routine which manipulates that parameter, and that routine takes a lot of time, that time would be completely wasted because you wouldn't be able to pass anything back anyways... So you might want to skip everything in the routine if a literal was passed. But other than that, I am truly stumped for the reason and *VERY* curious about the source of that routine; what it exactly does..... Then again, if you're going to solve it by adding a sort of marker somewhere in the string, then the whole 'performance reason' is out of the window, since: why calling that SUB to begin with if you are able to add a marker to notify it is a literal to begin with. In that case, just skip the routine....Then again, if you do that, then the parameter wouldn't be a literal anymore anyways as it would ALWAYS be a variable... so what gives????? Yeah, I'm truly lost here in the logic...lol)
PS: this problem does bring up a nice suggestion for QB64 though: allow optional parameters! This would make it so that your 'marker' can be an extra parameter in the new calls, and all the existing old calls would all still work as usual.
Is it correct that your question is actually "how to distinguish between a variable passed by reference vs. passed by value"? Because that is essentially what you're asking IMHO.
When you pass a literal string in normal BASICs, you actually pass a (internal) variable "by value".
This means changing its value inside the SUB has no reflection on the 'outside world'; there is no way to catch the change outside the sub. This in contrast to passing "by reference". Which means you actually pass a pointer to a variable. And as such, if you change the contents of the variable inside the SUB, the change WILL reflect outside the sub; the parameter variable has changed.
The big question I have is: *Why?* Why would you want to know that difference? I really can not think of a proper reason that you would want to know if it is a literal or not. ie. IF it was a literal, nothing would change anyways, so why bother?
I really would like to see this subroutine of yours to understand WHY it is needed/so important, if possible.
(well, TBH, the only reason I can think of is because of performance: If you pass a literal string to a routine which manipulates that parameter, and that routine takes a lot of time, that time would be completely wasted because you wouldn't be able to pass anything back anyways... So you might want to skip everything in the routine if a literal was passed. But other than that, I am truly stumped for the reason and *VERY* curious about the source of that routine; what it exactly does..... Then again, if you're going to solve it by adding a sort of marker somewhere in the string, then the whole 'performance reason' is out of the window, since: why calling that SUB to begin with if you are able to add a marker to notify it is a literal to begin with. In that case, just skip the routine....Then again, if you do that, then the parameter wouldn't be a literal anymore anyways as it would ALWAYS be a variable... so what gives????? Yeah, I'm truly lost here in the logic...lol)
PS: this problem does bring up a nice suggestion for QB64 though: allow optional parameters! This would make it so that your 'marker' can be an extra parameter in the new calls, and all the existing old calls would all still work as usual.
Who remembers QB30, GWBASIC, C64, ZX80?

