Indirect pointers

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Twim
Posts: 15
Joined: Sun Jul 27, 2008 6:28 am

Indirect pointers

Post by Twim » Wed Sep 17, 2008 3:21 am

Hello again,
Is it possible to use indirect pointers in swordfish basic ie.

Dim ptrToSub as longWord


ptrToSub = @Myfunction()


If readytorun = 1 Then Goto ptrToSub

TimB
Posts: 262
Joined: Wed Oct 04, 2006 7:25 am
Location: London UK

Post by TimB » Wed Sep 17, 2008 1:12 pm

Its not quite that simple but there is a system like that.

I do not have SF handy at the moment but look in the timers interrupts example for it in use.

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

Post by octal » Wed Sep 17, 2008 1:17 pm

Hello,

I do not think it's possible with SF to call functions using pointers to functions.

As Tim stated, you can fiddle using Events. They acts somewhat as pointers to procedures.

I think that simply branching to a sub is not correct because when you make an explicit call to a sub, Swordfish generates all needed code to create and manage its stack frame. Switching to a procedure via its addres could make the program instable, especially if it involves interrupts (with context saving/restoring). Do not forgot also that SF use a recycling mechanism for local parameters of functions/subs, so calling a function from a pointer to it does not makes things easy to the compiler to know which functions are active simultaniously.

Regards
Octal

Post Reply