Function Pointers

Just starting out? Need help? Post your questions and find answers here.
SurreaL
User
User
Posts: 43
Joined: Tue Dec 23, 2003 3:06 am

Function Pointers

Post by SurreaL »

I've noticed you can get the address of a function..I'm just wondering if you can use that address later to call the function?

I'm brand new to PB (used to BB!) and so I'm trying to get a handle on all this extra functionality :) (no pun intended!)

Cheers,
-SurreaL
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

not sure if this helps..

Post by NoahPhense »

SurreaL
User
User
Posts: 43
Joined: Tue Dec 23, 2003 3:06 am

Post by SurreaL »

Thanks for your reply!

However I have already understood the basics of how to set up pointers and use them..

I'm just wondering if there's any way to call a function from a pointed initialized with the address of said function..

IE something like this (doesn't compile..)

Code: Select all

Declare Test()
MyFunc.l = @Test()
Call (*MyFunc ())
MessageRequester("Information","Yup.",#PB_MessageRequester_Ok)

Procedure Test()
  a.l
  a = a + 1
EndProcedure
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

I don't *think* there is a way to do that.... Yet.

[edit]
errr I mean, of course there is! See below!
Last edited by Karbon on Tue Dec 23, 2003 6:32 am, edited 1 time in total.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
p2hicy
User
User
Posts: 11
Joined: Fri Apr 25, 2003 5:31 pm
Location: Iceland
Contact:

Post by p2hicy »

Code: Select all

Procedure thefunc(title.s, msg.s)
  MessageRequester(title, msg, #NULL)
EndProcedure

thefuncpointer = @thefunc()

CallFunctionFast(thefuncpointer, "hello i'm a title", "hello i'm the message")

SurreaL
User
User
Posts: 43
Joined: Tue Dec 23, 2003 3:06 am

Post by SurreaL »

Holy Crap.

That rules :D

I remember looking over CallFunctionFast and wondering if that would be possible.. I was concerned that it only worked with DLL's functions though.. This is wicked :) Looks like I can fake some OO w/ PB fairly easily now..

thanks a bunch!
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

If you can, post some examples when you're finished.. There are lots of people that seem to want to use OOP in PB!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

Hi Surreal.. welcome! :D

Are we going to see PurePlay soon then eh?!? 8O :twisted: :lol:

-Lars

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Surreal, have a look at Interfaces in the manual, you can "fake" OOP the same way other languages do.
El_Choni
SurreaL
User
User
Posts: 43
Joined: Tue Dec 23, 2003 3:06 am

Post by SurreaL »

El_Choni,

I've taken a look at the interfaces section.. It looks like it would be mostly useful for interfacing w/ objects created in another language. Could this be used to create a PB DLL and access objects within it..? I was referencing to simulating OO by having function pointers within a structure, sort of making that a "class" by doing so :)

LarsG,

Ah hah! Someone recognizes me :D In fact.. Porting over my network library is something I'm looking at.. I've been trying to research the better way to do networking however, and have sort of hit a wall w/ IOCP. (I've read elsewhere on these forums that it's not possible within PB..? I wonder why..) Either way.. I do *very* much want to do it, so we'll see :)
Hi-Toro
Enthusiast
Enthusiast
Posts: 269
Joined: Sat Apr 26, 2003 3:23 pm

Post by Hi-Toro »

Porting over my network library is something I'm looking at..
AAAAA!!!! Traitor!!!!

... from someone else who recognises you ;)

(I didn't know you could use CallFunctionFast in that way, though -- nice!)
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
ppjm99
User
User
Posts: 23
Joined: Mon Jun 02, 2003 7:39 pm
Location: Canada

This link to a previous post might be helpful.

Post by ppjm99 »

Post Reply