Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Determining if variable or static string is passed to a Sub
#8
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.
Who remembers QB30, GWBASIC, C64, ZX80?
Reply


Messages In This Thread
RE: Determining if variable or static string is passed to a Sub - by CookieOscar - 06-18-2025, 05:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable length type declarations dano 5 706 08-06-2025, 09:53 PM
Last Post: dano
  Most efficient way to build a big variable length string? mdijkens 9 1,926 01-17-2025, 11:36 PM
Last Post: ahenry3068
  Huge array of variable length strings mdijkens 9 1,875 10-17-2024, 02:01 PM
Last Post: mdijkens
  REDIM, TYPE, and STRING Woes TerryRitchie 16 3,211 04-13-2023, 05:17 AM
Last Post: DSMan195276
Lightbulb To mimic "cmd.exe" behavior with eg. "DIRCMD" env. variable mnrvovrfc 4 1,208 09-29-2022, 02:51 AM
Last Post: mnrvovrfc

Forum Jump:


Users browsing this thread: 1 Guest(s)