Oxygen Basic

Programming => Problems & Solutions => Topic started by: Mike Lobanovsky on March 21, 2018, 08:10:39 AM

Title: [RESOLVED] @/& Pointers in Unprototyped Calls?
Post by: Mike Lobanovsky on March 21, 2018, 08:10:39 AM
Charles,

Can I be absolutely sure that, when an unprototyped function expects a pointer to whatever argument, it is guaranteed to receive that pointer no matter what if I prepend my argument with an explicit @ or &?

Can I be equally sure that, if I prepend my string argument with an explicit (albeit redundant) @ or &, O2 isn't going to choke attempting double redirection rather than single?

Can I be also sure O2 would resolve my explicit @ or & correctly when passing, as unprototyped arguments, the addresses of procedure entry points (including those in the DLLs currently mapped in the process memory), UDT members (even when inside a With/End With block), and array elements?

TIA
Title: Re: @/& Pointers in Unprototyped Calls?
Post by: Charles Pegge on March 21, 2018, 10:39:39 AM
To keep the rules simple:


Use @ explicitly when passing numeric primitives, their arrays, and procedures byref. Indirection is correctly resolved

Use strptr for all types of string passed byval . This is optional but more efficient.

UDTs and class objects (passed byref) do not require @, but you may do so for clarity.

Use @@ for Virtual objects passed byref
Title: Re: @/& Pointers in Unprototyped Calls?
Post by: Mike Lobanovsky on March 21, 2018, 11:02:25 AM
Seems OK but still, can I use @/& instead of strptr, and if not, then why? Why still make a distinction if @/& are already near universal? (hint: Occam's razor)
Title: Re: @/& Pointers in Unprototyped Calls?
Post by: Charles Pegge on March 21, 2018, 01:44:11 PM
You must use strptr to cover all string types, but @ will work for char and char*.

For string and bstring, I will see whether Occam's razor should be applied.
Title: Re: @/& Pointers in Unprototyped Calls?
Post by: Mike Lobanovsky on March 21, 2018, 01:46:20 PM
Thanks Charles, I can't wait to hear out your verdict.
Title: Re: @/& Pointers in Unprototyped Calls?
Post by: Aurel on March 21, 2018, 02:36:47 PM
Charles
is my next example correct 

Code: [Select]
'autodefined pointers works
string a = "Oxygen"
@p = a
print p  ' show Oxygen

char c[] = "Basic"
p = strptr c

print p ' show Basic

'defined not
sys p2
string a = "Oxygen2"
@p2 = a
print p2  ' show Oxygen

sys pc
char c[] = "Basic2"
pc = strptr c

print pc
Title: Re: @/& Pointers in Unprototyped Calls?
Post by: Charles Pegge on March 21, 2018, 03:28:13 PM
string s="oxygen"
sys p=strptr s

char*c=p
print c 'oxygen
print @c 'equals p
Title: Re: @/& Pointers in Unprototyped Calls?
Post by: Mike Lobanovsky on March 21, 2018, 04:17:38 PM
Charles,

I assume the above is addressed to Aurel.

All that's left that I need to know is if this:
Code: [Select]
string m = "World!", t = "Hello"
#ifdef _WIN64
    ! MessageBoxW Lib "User32.dll"
    MessageBoxW 0, @m, @t, 0 ' OK I know it's redundant but still...
#elif defined(_WIN32)
    ! MessageBoxA Lib "User32.dll"
    MessageBoxA 0, @m, @t, 0 ' Ditto
#endif
can produce the desired x86 and x64 effect now or at some definite future point in time.

TIA
Title: Re: @/& Pointers in Unprototyped Calls?
Post by: Charles Pegge on March 21, 2018, 04:54:54 PM
Mike,

Yes in principle, except:

I dropped #elif if favour of #elseif

The RTLs have flags: mode64bit and mode32bit

You will require  wide strings for MessageBoxW
wstring ws=s 'this will autoconvert

Unlike C, the o2 metalanguage is not preprocessed, and can be used inside macros which are also late-expanding. The differences are subtle but important for the coherence of the metalanguage.
Title: Re: @/& Pointers in Unprototyped Calls?
Post by: Mike Lobanovsky on March 21, 2018, 05:14:41 PM
!!! EXCELLENT !!! YOU ARE DA MAN !!!  8) :D
Title: Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
Post by: Charles Pegge on March 21, 2018, 05:31:54 PM
Aha! I see you slipped in those '@' pointers for dynamic strings instead of strptr. I will have to consult the dream council to get a final ruling..
Title: Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
Post by: Mike Lobanovsky on March 21, 2018, 08:02:15 PM
Actually I didn't "slip" them "in", Charles. They've been there from the very beginning. You can see there were no later edits in my message. :)

Yes, I consider @ as a significant improvement over strptr from my perspective on how a practical intellisense system could be implemented in a hypothetical header-less O2 IDE to match Oxygen's unprototyped mode of operation.

And I'll be keeping my fingers crossed in the hope that every Z member in your z-Z-Z dream council will support a favorable verdict. :)
Title: Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
Post by: Charles Pegge on March 21, 2018, 11:04:56 PM
The dream council advises that we must maintain the current functionality of the '@' operator, since it is required for managing dynamic structures, such as strings of strings.

However, strings passed byval as unprototyped parameters behave impeccably, without requiring any explicit operator. (there are a few issues with variadic functions, but these follow a different route.)

So my best advice is to pass the strings directly :)
Title: Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
Post by: Mike Lobanovsky on March 22, 2018, 05:39:54 PM
All right, Charles,

What will be, will be.  :-\
Title: Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
Post by: Charles Pegge on March 22, 2018, 07:40:12 PM
Mike,

The only time you will need '@' is when passing numeric primitives and their arrays byref :)

Variadic functions are now fixed, and use similar rules.

https://github.com/Charles-Pegge/OxygenBasic
Title: Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
Post by: Mike Lobanovsky on March 22, 2018, 10:11:39 PM
Charles,

I knew it! I said you're DA man! 8)

Thank you, that'll be pretty much enough to implement what I have in mind. Allow me some time to find my way around the competitor's environment. ;)
Title: Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
Post by: JRS on March 22, 2018, 10:19:54 PM
Quote
Variadic functions are now fixed, and use similar rules.

Is this fix transparent to DLLC? SB uses variadic functions/subs exclusively.
Title: Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
Post by: Charles Pegge on March 22, 2018, 10:32:05 PM

Yes, this is a minor fix, and DLLC doesn't use compile-level variadic functions. Their use is quite limited. Functions like printf and scanf require this feature.