c语言中的“函数类型” 与 ”函数指针类型“

参考:http://light4.github.com/Linux-C/ch23s08.html

/*
 * =====================================================================================
 *
 *       Filename:  b.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  09/15/2012 17:04:03
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#include <errno.h>
#include <math.h>  
#include <stdio.h> 
#include <stdlib.h>
#include <string.h>

typedef void F(const char*); //define function type F
typedef void (*PF)(const char*); //define a function pointer type PF

F a;

F* retPF(F* f){  // a function return a "function pointer type"
    (*f)("in Ret");
    return f;
}


    int
main ( int argc, char *argv[] )
{
    a("hell");
    PF pF = a;
	printf ("\nProgram %s\n\n", argv[0] );
    (*pF)("hello");
    F* rP = retPF(a);
    rP("rP printed");
    PF pF2 = retPF(a);
    pF2("PF2 printed");

	return EXIT_SUCCESS;
}		/* ----------  end of function main  ---------- */

void a(const char* str){
    printf("%s\n", str);
}

你可能感兴趣的:(函数指针)