C memcpy()一个函数 [英] C memcpy() a function

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

问题描述

有什么方法可以计算函数的大小?我有一个指向函数的指针,我必须使用memcpy复制整个函数.我必须分配一些空间,并知道memcpy的第三个参数-大小.我知道sizeof(function)不起作用.你有什么建议吗?

Is there any method to calculate size of a function? I have a pointer to a function and I have to copy entire function using memcpy. I have to malloc some space and know 3rd parameter of memcpy - size. I know that sizeof(function) doesn't work. Do you have any suggestions?

推荐答案

函数不是一流的对象在C中.这意味着它们不能传递给另一个函数,不能从函数返回,也不能复制到内存的另一部分.

Functions are not first class objects in C. Which means they can't be passed to another function, they can't be returned from a function, and they can't be copied into another part of memory.

尽管函数指针可以满足所有这些要求,但它是一个一流的对象.函数指针只是一个内存地址,它的大小通常与计算机上的任何其他指针相同.

A function pointer though can satisfy all of this, and is a first class object. A function pointer is just a memory address and it usually has the same size as any other pointer on your machine.

这篇关于C memcpy()一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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