本文介绍了什么是“typedef void(* Something)()”意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这是什么意思,我在看的代码

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

在.h

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

in .C

MCB Modes::m_process = NULL;

有时候我会做

m_process();

我得到分段错误,这可能是因为内存已释放, ?

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

我希望我的问题清楚。

推荐答案

指针到函数类型。函数返回void,并且参数列表未指定,因为问题是(当前,但可能错误地)标记为C;如果它被标记为C ++,那么该函数根本不需要任何参数。要使其成为不带参数的函数(在C中),您可以使用:

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);

这是C之间有显着差异的领域之一,要求所有函数在定义或使用之前进行原型开发,C ++则需要。

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.

这篇关于什么是“typedef void(* Something)()”意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 01:06