Callbacks with a limited scope -
Geebrox - 21.05.2018
Hi, is it possible to create callbacks with a limited scope? I need callbacks which are available only in the include file. I know that it is possible to create functions with a limited scope through "static".
Код:
//For instance, file "some_inc.inc"
static SomeFunc() { } //wiil be available only in this file
How can I do the same thing with callbacks? Is this possible?
Why I need this? Because I can't use timers for functions.
Re: Callbacks with a limited scope -
Geebrox - 22.05.2018
This is possible
![Smiley](images/smilies/smile.png)
I just checked.
If someone interested, I used:
Код:
//File "some_inc.inc"
static @SomeFunc();
static @SomeFunc() { }
//@SomeFunc is available only in this file.
P.S.
But it works a little bit different rather than "static" functions.
If someone has other methods, please share.
Re: Callbacks with a limited scope -
Geebrox - 22.05.2018
Any ideas? (up)
Re: Callbacks with a limited scope -
Dayrion - 22.05.2018
Declare static variable & function wille make them only available in the current file. There is no other better method. What's the problem with the "static" keyword?
Re: Callbacks with a limited scope -
Geebrox - 22.05.2018
Thank you for answers.
Re: Callbacks with a limited scope -
Geebrox - 22.05.2018
But there is a bug of the compiler. As DC (Daniel_Cortez) tested, there is some possible way to do it.
myinc.inc
PHP код:
static @SomeFunc();
static @SomeFunc()
{
emit const.pri 0;
}
main.p:
PHP код:
#include "myinc.inc"
@SomeFunc();
@SomeFunc()
{
emit const.pri 1;
}
main()
{
@SomeFunc();
}
Output pawndisasm:
PHP код:
00000000 halt 00000000
00000008 proc ; @SomeFunc
0000000c const.pri 00000000
00000014 zero.pri
00000018 retn
0000001c proc ; @SomeFunc
00000020 const.pri 00000001
00000028 zero.pri
0000002c retn
00000030 proc
00000034 push.c 00000000
0000003c call 0000001c ; @SomeFunc
00000044 zero.pri
00000048 retn
But you cannot know which one is exactly will be called and in which file
Re: Callbacks with a limited scope -
Geebrox - 22.05.2018
Quote:
Originally Posted by ******
That seems pretty clear and correct to me. It calls the one visible in the current scope (0000001c in the assembly).
|
And you want to say that this is what I wanted?
Re: Callbacks with a limited scope -
Geebrox - 22.05.2018
And as I understood, it doesn't work as seemed to ******:
Re: Callbacks with a limited scope -
CodeStyle175 - 22.05.2018
you dont want to create global function but you want to call it from other include?
Re: Callbacks with a limited scope -
Geebrox - 22.05.2018
Quote:
Originally Posted by ******
That's different to what you posted before, where you were just talking about direct calls. In that case, the function by "main" being called was correct. This code is something different, and would seem to be a bug.
Edit: But this method isn't overly useful, as it requires having two copies of the function - one public shadowing the static version.
|
Yes, you were right, sorry)
But I need timers. If I use timers the result is different