PDA

View Full Version : Is it possible?


stefanhendriks
16-12-2004, 18:01
Well, i'm busy with a secret project.

The question is, can i have something like:

file a.cpp

int ReturnSomeIndex()
{
return bla;
}


in file b.cpp

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, 18:45
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, 18:51
i was afraid of that ;)

@$3.1415rin
16-12-2004, 19:14
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, 06:34
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:

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, 09:23
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.