But why that whole mess with function pointers? Where do they have the key advantage compared to directly calling the function?
Basics Of Function Pointers In C
11–20 of 61 posts
Re: Basics Of Function Pointers In C
#12But why that whole mess with function pointers? Where do they have the key advantage compared to directly calling the function?
1. http://forums.exophase.com/threads/tiff-exploit-hen-informat...
Disclaimer(?): The TRFyuki here, is me. :)
Re: Basics Of Function Pointers In C
#13The other resource I use for similar situations is http://c-faq.com/decl/spiral.anderson.html [EDIT]: someone beat me to it
FWIW: The explanation by Dave G in the comments isn't quite right (I couldn't reply there, comments appear closed):
> void something(); // prototype of function that takes undetermined number of arguments
> void something(void); // prototype of function that takes no arguments
> void something() { return; } // function that takes no arguments
isn't quite right as `void something(){ return; }` is still a function that takes an undetermined number of arguments, it just cannot access them; calling `something(1,2,3)` is still valid.
> void unknown(){ return ;}
> int main(void){ something(1,2,3);}
is valid.
Re: Basics Of Function Pointers In C
#14The article is missing at least one useful thing: how to declare a typedef for a function pointer. This can be used both to avoid error-prone duplication of declarations and to simplify excessively complex declarations. Here's a simple example: http://en.wikipedia.org/wiki/Typedef#Using_typedef_with_func... Here's a more complex example: http://www.devx.com/tips/Tip/13829 Here's a tutorial on how to interpret the com…
Re: Basics Of Function Pointers In C
#15But why that whole mess with function pointers? Where do they have the key advantage compared to directly calling the function?
Let's look at the signature of qsort() from libc: void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); qsort is a function inside of libc.so. It's already been compiled. It doesn't know about the "compar" pointer you're going to pass it. That function might not even exist yet. qsort doesn't know if you're sorting integers, sorting strings, sorting struct foo which is still bei…
Re: Basics Of Function Pointers In C
#16Understanding function pointers in C unlocks the ability to write clean, object-oriented code with inheritance (kinda, sorta, shhhh). With great power, etc. etc.
Re: Basics Of Function Pointers In C
#17The article is missing at least one useful thing: how to declare a typedef for a function pointer. This can be used both to avoid error-prone duplication of declarations and to simplify excessively complex declarations. Here's a simple example: http://en.wikipedia.org/wiki/Typedef#Using_typedef_with_func... Here's a more complex example: http://www.devx.com/tips/Tip/13829 Here's a tutorial on how to interpret the com…
http://c-faq.com/decl/spiral.anderson.html
(I accidentally deleted my reply)
Re: Basics Of Function Pointers In C
#18But why that whole mess with function pointers? Where do they have the key advantage compared to directly calling the function?
Re: Basics Of Function Pointers In C
#19The article is missing at least one useful thing: how to declare a typedef for a function pointer. This can be used both to avoid error-prone duplication of declarations and to simplify excessively complex declarations. Here's a simple example: http://en.wikipedia.org/wiki/Typedef#Using_typedef_with_func... Here's a more complex example: http://www.devx.com/tips/Tip/13829 Here's a tutorial on how to interpret the com…
Re: Basics Of Function Pointers In C
#20Understanding function pointers in C unlocks the ability to write clean, object-oriented code with inheritance (kinda, sorta, shhhh). With great power, etc. etc.
I committed what I now realize were true crimes against software engineering when I first learned of function pointers.