《c陷阱与缺陷》第二章,语法陷阱

2.1 函数声明

float *g();  // indicate a function returning a pointer to a float

float (*h)();//indicate a pointer to a function returning a float

*h是一个float类型的函数,h是指向这个函数的指针

float是类型声明,说明后面的类型是float类型的

g()中,()表示函数调用

类型转换符((*h)())表示“指向返回浮点类型的函数的指针”类型转换符

 

Q:调用首地址为0位置的子例程

(*0)();但是*必须要一个指向函数的指针作为操作数,所以增加格式转换,

扩充为(*(void (*)())0)();

eg: 

       void(*)()             // indicates a pointer to a function returning nothing

    ((void(*)())0)        //change the type of 0 from integer to a pointer

(*((void(*)())0))      //obtain the data pointed by the pointer, that is the  subroutine in location 0

(*((void(*)())0))();   // call the subroutine

 

3) define a type for a function pointer

 typedef float(*ptr)();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值