Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "typedef void (*Something)()" mean

I am trying to understand what this means, the code I am looking at has

in .h

typedef void (*MCB)(); static MCB     m_process; 

in .C

MCB Modes::m_process = NULL; 

And sometimes when I do

m_process(); 

I get segmentations fault, it's probably because the memory was freed, how can I debug when it gets freed?

like image 667
DogDog Avatar asked Oct 20 '10 21:10

DogDog


1 Answers

It defines a pointer-to-function type. The functions return void, and the argument list is unspecified because the question is (currently, but possibly erroneously) tagged C; if it were tagged C++, then the function would take no arguments at all. To make it a function that takes no arguments (in C), you'd use:

typedef void (*MCB)(void); 

This is one of the areas where there is a significant difference between C, which does not - yet - require all functions to be prototyped before being defined or used, and C++, which does.

like image 102
Jonathan Leffler Avatar answered Oct 02 '22 00:10

Jonathan Leffler