[Done] Declare doesn't match with real procedure

Post bugreports for the Windows version here
acreis
Enthusiast
Enthusiast
Posts: 230
Joined: Fri Jun 01, 2012 12:20 am

[Done] Declare doesn't match with real procedure

Post by acreis »

Good Day,

I don't know where is my error:

Code: Select all

Prototype proto_void()

Declare MyFun(sString$, *ptrFunction.proto_void)

Procedure MyFun(sString$, *ptrFunction.proto_void) ;Declare doesn't match with real procedure
  
  
EndProcedure

User avatar
STARGÅTE
Addict
Addict
Posts: 2257
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Declare doesn't match with real procedure

Post by STARGÅTE »

acreis wrote: Mon Oct 06, 2025 3:22 pm Good Day,

I don't know where is my error:

Code: Select all

Prototype proto_void()

Declare MyFun(sString$, *ptrFunction.proto_void)

Procedure MyFun(sString$, *ptrFunction.proto_void) ;Declare doesn't match with real procedure
  
  
EndProcedure

Do not use a pointer. Prototypes are defined without pointer * character.

Code: Select all

Prototype proto_void(sString$)

Declare MyFun(sString$, ptrFunction.proto_void)

Procedure MyFun(sString$, ptrFunction.proto_void) ;Declare doesn't match with real procedure
  
  ptrFunction(sString$)
  
EndProcedure

Procedure void(sString$)
	Debug sString$
EndProcedure

MyFun("Hello", @void())
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
acreis
Enthusiast
Enthusiast
Posts: 230
Joined: Fri Jun 01, 2012 12:20 am

Re: Declare doesn't match with real procedure

Post by acreis »

Thank you very much!
User avatar
idle
Always Here
Always Here
Posts: 6011
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Declare doesn't match with real procedure

Post by idle »

I've always used *ptr.prototype as a parameter as it's used to denote that it receives an address to a function of the prototype. It also explains why one of my include files doesn't compile anymore as the ide makes the check but the compiler doesn't and I was very confused and being dyslexic I cant see the differences of which there wasn't any.

I really don't get the logic behind forbidding it as it makes no difference as far as the compiler goes and make a big difference to users of a lib so they know that they're supposed to pass in the address of their function.
User avatar
Piero
Addict
Addict
Posts: 1034
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Declare doesn't match with real procedure

Post by Piero »

Huh?

Prototypes (according to help) are "a way to EXPLICITLY declare an external function"…
…that's mostly win stuff…

But they can be useful to process "global data" with "variable" runtime procedures, by calling the right procedure by name (or passing the name as parameter)…

Am I wrong? I feel like if I just wrote a complicated "pineapple pizza" :oops:
User avatar
idle
Always Here
Always Here
Posts: 6011
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Declare doesn't match with real procedure

Post by idle »

A prototype is a description of how to call a function so the compiler knows how to execute it.
In my recent display list tip it uses prototypes in a structure union to dynamically call the native functions via a raw untyped pointer which is cast to the prototype automatically rather than using a bunch of selects, there's 60 odd functions in it.
prototypes are generally accesed via pointers so why shouldn't they work as parameters to a function.
*pfn.doit is clearer than pfn.doit as a parameter the pointer is a hint to the user, pfn.doit suggest it's a structure but we can't pass structures to procedures
So it makes little sense to me and should be considered a bug because it's technically a pointer to a function.
I'm not sure when it was changed but it did my head in when I saw the error message as I was compiling the project fine and it was only when I tested the file that included the file that it popped up the error.
So yes pineapple pizza indeed
User avatar
STARGÅTE
Addict
Addict
Posts: 2257
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Declare doesn't match with real procedure

Post by STARGÅTE »

idle wrote: Wed Oct 08, 2025 11:51 pm I really don't get the logic behind forbidding it as it makes no difference as far as the compiler goes and make a big difference to users of a lib so they know that they're supposed to pass in the address of their function.
In the procedure definition *foo.bar show you that you have to pass a pointer to a structure,
foo.bar show you that you have to pass a function, because foo.bar is not allowed, if bar is a structure.

Inside the procedure *foo is highlighted as pointer (to a memory or structure).
foo() is highlighted as a function, because it is callable, while *foo() is highlighted as a pointer, and looks also kind of wrong to me.
Don't you define DLL functions also without * ?

Code: Select all

Global MyFunction.MyPrototype = GetFunction(Library, "FuntionName")
MyFunction(123)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
idle
Always Here
Always Here
Posts: 6011
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Declare doesn't match with real procedure

Post by idle »

I just think it's ambiguous and prefer to use them as pointers in parameters.
The behavior changed with PB 6.30b1 but either way there's a bug as it doesn't fire the error if the include is nested as in main.pb -> inc1.pbi -> inc2.pbi which contains the offending *pfn.CBFunction as a parameter.
Also if the function isn't declared there is no problem.
So it's a bug but should it be enforced or not, I'm on the not side here, as I use it all the time.
Fred
Administrator
Administrator
Posts: 18343
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Declare doesn't match with real procedure

Post by Fred »

I will take a closer look
Fred
Administrator
Administrator
Posts: 18343
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Done] Declare doesn't match with real procedure

Post by Fred »

Fixed.
User avatar
Piero
Addict
Addict
Posts: 1034
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: [Done] Declare doesn't match with real procedure

Post by Piero »

Thanks Idle (also for the Vector drawing display List thing!) and all; use of prototypes is more clear for me now! (I also erroneously thought that "calling runtime procedures by name" was more limited :oops: )
Post Reply