-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_CLngPtr pseudo-function #580
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just don't know if I like the name. When reading _CLngPtr
my immediate thought is more in the direction of obtaining a pointer from the given LONG
variable, hence _OFFSET(lvar&)
or in C ptrszint = &somelongvar
. The name is also too similar to CLng
which does something completely different.
But as this pseudo function effectively just makes an explicit type cast I'd probably prefer something more straight forward to that behavior, e.g. simply _OffToInt
, _OffsetAsNumber
, _OffsetVal
or something similar.
I second @RhoSigma-QB64's thoughts - especially because "pointer" is not a word we use in QB64, so I think it's a bit extra confusing. I'd be fine with @RhoSigma-QB64's name, though I'd mention we could potentially expand this and introduce a new Perhaps instead of this we could consider just removing the restrictions on |
I have had trouble picking the name, eventually settling for something Microsoft uses, thinking it may be familiar. But I think I like @mkilgore's suggestion better now. A Honestly, I am unsure why we have restrictions on _OFFSET. However, after looking at the code, I found multiple places where it is checked if we are dealing with an _OFFSET or not. Notably: Line 17965 in bb82976
Line 10772 in bb82976
Line 16809 in bb82976
Line 17472 in bb82976
And there are a few more. I did consider removing those. But I am not really sure what that'll break. |
I think in general the The issue for QB64 is that it breaks this thinking with |
Closing this based on discussion above. Will open a fresh PR with _OFFSET restrictions removed and add new tests. |
In QB64, the usage of
_OFFSET
variables in expressions is intentionally limited, with guardrails in place to discourage improper use. These restrictions are designed to prevent users from inadvertently performing invalid pointer arithmetic that could lead to reading or writing in unauthorized areas of memory. This is all good. However, there are scenarios where using _OFFSET variables in pointer arithmetic becomes necessary. For a detailed discussion, refer to issue #123.Currently, these guardrails force users to rely on inefficient conversions or questionable hacks, both of which are undesirable.
Expensive conversion:
Hack:
This PR introduces the
_CLngPtr
pseudo-function, which allows users to directly retrieve the value of an _OFFSET variable and allows its usage in expressions where usage of _OFFSET was previously not allowed. Internally, no actual function call is performed. The name is inspired by Microsoft's CLngPtr, which does something similar.