Author Topic: [RESOLVED] @/& Pointers in Unprototyped Calls?  (Read 3161 times)

0 Members and 2 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
[RESOLVED] @/& Pointers in Unprototyped Calls?
« 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
« Last Edit: March 21, 2018, 05:15:10 PM by Mike Lobanovsky »

Charles Pegge

  • Guest
Re: @/& Pointers in Unprototyped Calls?
« Reply #1 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

Mike Lobanovsky

  • Guest
Re: @/& Pointers in Unprototyped Calls?
« Reply #2 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)
« Last Edit: March 21, 2018, 11:31:20 AM by Mike Lobanovsky »

Charles Pegge

  • Guest
Re: @/& Pointers in Unprototyped Calls?
« Reply #3 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.

Mike Lobanovsky

  • Guest
Re: @/& Pointers in Unprototyped Calls?
« Reply #4 on: March 21, 2018, 01:46:20 PM »
Thanks Charles, I can't wait to hear out your verdict.

Aurel

  • Guest
Re: @/& Pointers in Unprototyped Calls?
« Reply #5 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

Charles Pegge

  • Guest
Re: @/& Pointers in Unprototyped Calls?
« Reply #6 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

Mike Lobanovsky

  • Guest
Re: @/& Pointers in Unprototyped Calls?
« Reply #7 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

Charles Pegge

  • Guest
Re: @/& Pointers in Unprototyped Calls?
« Reply #8 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.

Mike Lobanovsky

  • Guest
Re: @/& Pointers in Unprototyped Calls?
« Reply #9 on: March 21, 2018, 05:14:41 PM »
!!! EXCELLENT !!! YOU ARE DA MAN !!!  8) :D

Charles Pegge

  • Guest
Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
« Reply #10 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..

Mike Lobanovsky

  • Guest
Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
« Reply #11 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. :)

Charles Pegge

  • Guest
Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
« Reply #12 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 :)

Mike Lobanovsky

  • Guest
Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
« Reply #13 on: March 22, 2018, 05:39:54 PM »
All right, Charles,

What will be, will be.  :-\

Charles Pegge

  • Guest
Re: [RESOLVED] @/& Pointers in Unprototyped Calls?
« Reply #14 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