Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Function Type?

Tags:

c++

function

I'm new to, and learning C++ (know a lot of Java) and the following code confuses me...

enter image description here

I know this code fragment is dealing with a pointer-to-function (it's a callback, that makes sense) but what is throwing me off is the argument between the return type and the function name. What the bloody hell is that?

It looks like a type of function, but I have never heard of that and even after searching and reading about pointer-to-functions I was not able to find anything mentioning that functions could have a type.

If this is true, how does one define a function type?

Thanks, -Cody

like image 908
Cody Smith Avatar asked Dec 07 '12 18:12

Cody Smith


People also ask

What is function list its type?

The types of functions can be broadly classified into four types. Based on Element: One to one Function, many to one function, onto function, one to one and onto function, into function. Based on Domain: Algebraic Functions, Trigonometry functions, logarithmic functions.

What is the main () function in C?

Every C program has a primary function that must be named main . The main function serves as the starting point for program execution. It usually controls program execution by directing the calls to other functions in the program.

What is type function programming?

In computer science and mathematical logic, a function type (or arrow type or exponential) is the type of a variable or parameter to which a function has or can be assigned, or an argument or result type of a higher-order function taking or returning a function.


1 Answers

GLFWCALL is not a type, it's a macro which is expanded to a calling convention specific to the platform, or an empty string. Here's a trimmed fragment of glfw.h:

#if defined(_WIN32) && defined(GLFW_BUILD_DLL)
 #define GLFWCALL     __stdcall
#elif defined(_WIN32) && defined(GLFW_DLL)
 #define GLFWCALL     __stdcall
#else
 /* We are either building/calling a static lib or we are non-win32 */
 #define GLFWCALL
#endif

Using a correct calling convention is important on x86/win32, since some of them expect the stack to be cleaned by callee and others by the caller. There can also be differences in the order of passing the arguments.

like image 85
Igor Skochinsky Avatar answered Oct 09 '22 12:10

Igor Skochinsky