Page 1 of 1

[Done] Pointer to a structure in the prototype

Posted: Tue Sep 09, 2025 4:13 pm
by User_Russian

Code: Select all

Macro ma_result : l : EndMacro
PrototypeC.ma_result p_onContextInit(*pContext.ma_context,  *pConfig.ma_context_config,  *pCallback.sma_backend_callbacks)
For prototype does not need to know what implementation of the structure is (the structure is declared below the prototype), because it is a pointer and it is always 4 or 8 bytes and not depend of the implementation of the structure.

Re: Pointer to a structure in the prototype

Posted: Tue Sep 09, 2025 6:20 pm
by NicTheQuick
Is that a bug report? I don't see any bug here. Please give more context.

Re: Pointer to a structure in the prototype

Posted: Tue Sep 09, 2025 6:36 pm
by Demivec
User_Russian wrote: Tue Sep 09, 2025 4:13 pm

Code: Select all

Macro ma_result : l : EndMacro
PrototypeC.ma_result p_onContextInit(*pContext.ma_context,  *pConfig.ma_context_config,  *pCallback.sma_backend_callbacks)
For prototype does not need to know what implementation of the structure is (the structure is declared below the prototype), because it is a pointer and it is always 4 or 8 bytes and not depend of the implementation of the structure.
Pointers can't be declared with native types like '.l' .

Re: Pointer to a structure in the prototype

Posted: Tue Sep 09, 2025 7:06 pm
by User_Russian
NicTheQuick wrote: Tue Sep 09, 2025 6:20 pm Is that a bug report? I don't see any bug here. Please give more context.
Image

ma_context, ma_context_config and sma_backend_callbacks these are structures that are declared after the prototype.
Demivec wrote: Tue Sep 09, 2025 6:36 pmPointers can't be declared with native types like '.l' .
There are no pointers with native PB types in this code.

Re: Pointer to a structure in the prototype

Posted: Tue Sep 09, 2025 7:48 pm
by mk-soft
One pass compiler. You mast define the structure before.

Re: Pointer to a structure in the prototype

Posted: Tue Sep 09, 2025 8:06 pm
by Fred
As it's a pointer, it should work. I will take a closer look

Re: Pointer to a structure in the prototype

Posted: Tue Sep 09, 2025 10:57 pm
by User_Russian
Similar problem with keyword Declare

Code: Select all

Declare Proc(*z.struct)

Structure struct
  Param1.l
  Param2.f
EndStructure

Procedure Proc(*z.struct)
  
EndProcedure
and Define

Code: Select all

Define *z.struct

Structure struct
  Param1.l
  Param2.f
EndStructure

*z\Param1=0
Import : EndImport

Code: Select all

Import "User32.lib"
  GetWindowRect(hWnd, *r.MyRECT)
EndImport

Re: Pointer to a structure in the prototype

Posted: Tue Sep 09, 2025 11:14 pm
by mk-soft
It has never been possible to use structures that were only defined after their first use.

Normal behaviour

Code: Select all

Procedure foo(*d.udtFoo)   
  
EndProcedure

Structure udtFoo
  d1.i
  d2.i
EndStructure

Re: Pointer to a structure in the prototype

Posted: Wed Sep 10, 2025 7:03 am
by NicTheQuick
mk-soft wrote: Tue Sep 09, 2025 11:14 pmIt has never been possible to use structures that were only defined after their first use.
You're not completely right. It works in structures:

Code: Select all

Structure Foo
	*pointer.Bar
EndStructure

Structure Bar
	a.i
	b.i
EndStructure

Define a.Foo
a\pointer = 1

Debug a\pointer

Re: Pointer to a structure in the prototype

Posted: Wed Sep 10, 2025 2:31 pm
by Fred
I implemented forward declaration for variable pointer for Declare() and Prototype().

Re: [Done] Pointer to a structure in the prototype

Posted: Wed Sep 10, 2025 3:16 pm
by NicTheQuick
Nice