请教typedef这一用法到底是做什么用的?不胜感激!
请问有哪位知不知道下面这个语句中typedef到底起什么作用?
typedef int (*fcmp) (const void*,const void*);
从来没有这样看过这样用typedef的
我在编译源程序时还真少不了那个typedef,去掉了,编译就通不过了
源程序如下:
#include <stdlib.h>
#include <stdio.h>
typedef int (*fcmp) (const void*,const void*);
int array[]={21,25,12,49,16,8};
int numcmp (const int *p1, const int *p2)
{
int value ;
value = *p1 - *p2 ;
if( value == 0)
return 0;
else if( value < 0)
return -1;
else
return 1;
}
int main( void )
{
int i;
printf( "before qsort the array is:\n ");
for( i = 0; i < 6; i++)
printf( "%6d ",array[i]);
qsort(array, 6, sizeof (int),(fcmp)(numcmp));//(qsort是系统库函数,用于对数据排序) fcmp明明有两个参数,而此处怎么只有一个numcmp函数作为参数传给它?
printf( "\n after qsort the array is:\n ");
for( i = 0; i < 6; i++)
printf( "%6d ",array[i]);
printf( "\n ");
return 0;
}
给出有效解决者给予满分,并不胜感激!
[解决办法]
ypedef定义的是一个带2个参数的函数指针吧
[解决办法]
函数的地址作为参数传递