Game Development Community

HELP: About Some Math Function Declarations

by Jane Austen · in Torque Game Engine · 01/04/2002 (9:11 am) · 6 replies

I know that this question seems a bit stupid, but I am really confused with some function declarations in mMath_C.cc, such as:

void (*m_point2F_normalize)(F32 *p) = m_point2F_normalize_C;

I don't know what does "= m_point2F_normalize_C" mean, and I also don't know where this function is defined.
I use the Visual C++, but from the VC reference, I couldn't find the information about such syntax.

#1
01/04/2002 (9:16 am)
Looks like a function pointer to me.
void (*m_point2F_normalize)(F32 *p) = m_point2F_normalize_C;

This statement, I believe, is declaring *m_point2F_normalize to be a pointer to a function that takes 1 parameter of type F32 and is a pointer as well, and that it returns void. It is also initializing this function pointer to point to the function m_point2F_normalize_C.
#2
01/04/2002 (9:42 am)
Thank you very much. But I am still a bit confused that, why not use the function directly? It might not be necessary to declare such pointers to the function.
#3
01/04/2002 (9:53 am)
Well there are a number of reasons to do a function pointer instead of calling the function directly. The most common reason is that you may have a lot of functions who's parameters are the same but do different things. You can use one function name (the function pointer) to call all these different functions. You can also maintain a list of all the different functions that a particular function pointer can call through an array of pointers and then just call a particular function by referencing its index in the array.
#4
01/04/2002 (9:53 am)
My guess is that there's an assembly version of the same function ( prolly with a _asm suffix instead of a _C suffic ), and that way you can, on the fly, change from the C version to the ASM function, and just pass the pointer to any called functions without having to go and hunt down specific function calls.
#5
01/04/2002 (9:58 am)
Also, what I would think would be the most famous use of a function pointer would be that in Windows programming.

If your familiar with Windows programming you will know that you have to make a WinMain and a WinProc function. WinMain has to stay WinMain but you may call WinProc whatever you like.

You then set the name of your WinProc function in a window class structure that you then register to Windows.

Windows uses the name you send it to declare a function pointer to it..that way Windows doesn't have to know or restrict you to a particular name.
#6
01/04/2002 (10:46 am)
Thank you all! I really appreaciate your help!!! :)