关于函数ptr的琐碎问题 [英] trivial problem about function ptr

查看:74
本文介绍了关于函数ptr的琐碎问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int func_s(int){return 1;}
typedef int (*FUNC_C)(int);
FUNC_C f = func_s;   //(1)
FUNC_C f = &func_s;  //(2)


(1),(2)都编译成功!(在vs2005下).
我只是不知道有什么区别? (2)中的&"函数是什么?


Both (1),(2) compiled OK!(under vs2005).
I just don''t know the difference? what''s the ''&''function in (2)?

thanks in advance.

推荐答案

''出于所有实际目的,函数的名称和指向同一函数的指针可以互换"

> http://stackoverflow.com/questions/9552663/function-pointers-and-功能地址 [ ^ ]

以及指向的链接:

http://stackoverflow.com/questions/6893285/why-do-all-these-crazy-function-pointer-definitions-all-work-what-is-really-goi [
''For all practical purposes, the name of a function and a pointer to the same function are interchangeable''

http://stackoverflow.com/questions/9552663/function-pointers-and-address-of-a-function[^]

and the link it points to:

http://stackoverflow.com/questions/6893285/why-do-all-these-crazy-function-pointer-definitions-all-work-what-is-really-goi[^]

Use your debugger to confirm this - a good exercise.


这篇关于关于函数ptr的琐碎问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆