Quantcast
Channel: Hacker News
Viewing all articles
Browse latest Browse all 25817

How Do I Declare a Function Pointer in C?

$
0
0
How Do I Declare A Function Pointer in C?

As a variable:

returnType (*variableName)(parameterTypes) = function_name;

As a static const variable:

static returnType (* const variableName)(parameterTypes) = function_name;

As an array:

returnType (*arrayName[])(parameterTypes) = {function_name0, ...};

As an argument to a function:

int my_function(returnType (*argumentName)(parameterTypes));

As a return value from a function:

returnType (*my_function(int, ...))(parameterTypes);

As a function pointer typedef:

typedef returnType (*typeName)(parameterTypes);

As a function typedef:

typedef returnTypetypeName(parameterTypes);

This site is not intended to be an exhaustive list of all possible uses of function pointers.
If you find yourself needing syntax not listed here, it is likely that a typedef would make your code more readable.

Unable to access this site due to the profanity in the URL? http://goshdarnfunctionpointers.com is a more work-friendly mirror.


Viewing all articles
Browse latest Browse all 25817

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>