zoukankan      html  css  js  c++  java
  • 函数指针声明时的形参列表可以没有

    #include <stdio.h>
    #include <stdlib.h>
    
    typedef void (* PF)();
    
    void add(int a,int b,int *result)
    {
       *result=a+b;
       printf("result:%d\n",*result);
    }
    
    void main()
    {
    	int x,y,z;
    
    	PF pfun = add;
    	x=5;
    	y=4;	
    	pfun(x,y,&z);
    }
    

    typedef void (* PF)();  换成 typedef void (* PF)(int,int,...);  typedef void (* PF)(,...);   typedef void (* PF)(int,int,int*); 都可以

    但是换成  typedef void (* PF)(...);    typedef void (* PF)(int);  不可以。

    说明可变形参可以采用直接不指定()或指定前几个再加省略号的形式,直接加省略号不可以,省略号前面必须有逗号。如果指定了确定个的形参,那么就必须与所指向的函数的形参一致。

  • 相关阅读:
    asy for
    asy html !
    lib
    git clone 指定 version tag
    git tag
    git clone <url>--depth 、 git clone <url> --recursive
    xelatex CLI
    rsync
    curl options
    [转自]C语言offset_of宏和container_of宏
  • 原文地址:https://www.cnblogs.com/mlj318/p/2233106.html
Copyright © 2011-2022 走看看