.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   Is it possible? (http://forums.bots-united.com/showthread.php?t=3214)

stefanhendriks 16-12-2004 17:01

Is it possible?
 
Well, i'm busy with a secret project.

The question is, can i have something like:

file a.cpp
Code:

int ReturnSomeIndex()
{
 return bla;
}

in file b.cpp
Code:

int UTIL_ReturnSomeIndex()
{
  if (ReturnSomeIndex)
        return ReturnSomeIndex();
 
 return 0;
}

so in other words.

file B must be in the project all the time, but will work even without file A. So when ReturnSomeIndex() does not exist, it compiles fine. I thought there was something done like this in botmans code before, with the engine functions put in a void *. But i am not sur eif this is possible.

So i want to override the UTIL_ReturnSomeIndex() with resulting a function. But even if that function does not exist (for neatness sake). I know i can 'do this simpler' with a simple boolean value or something like that. Or even provide an empty ReturnSomeIndex() function in file A. But thats the key, file A should NOT be needed and still compile and the program should run...

any idea?

Pierre-Marie Baty 16-12-2004 17:45

Re: Is it possible?
 
The only way to do this is to set up a table of function pointers (like the g_engfuncs we all know in HL1). Else your linker will complain about undefined identifiers.

stefanhendriks 16-12-2004 17:51

Re: Is it possible?
 
i was afraid of that ;)

@$3.1415rin 16-12-2004 18:14

Re: Is it possible?
 
yes, I think the only way would be to use function pointer tables and some sort of loading routines, like .dll / .so loading

sfx1999 17-12-2004 05:34

Re: Is it possible?
 
Yeah I have no idea how to do this. You will most likely need to make a library and use a header file. Like this:

Code:

extern int ReturnSomeIndex();
Or, you can give the function a pointer to the function. I've seen tutorials.

http://www.function-pointer.org/

BTW, pfn stands for pointer to function. That is how you can denote it.

stefanhendriks 17-12-2004 08:23

Re: Is it possible?
 
I thought of this method, but in fact this caused double-trouble. I might go this route again, but i don't think its worth it and can be done easier. Though, i'm still interested in this, its similiar how the Think functions work in HL2... they do a "SetTHink" or something ;) But thats something you guys already knew of course.


All times are GMT +2. The time now is 20:48.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.