最佳答案
我们是否可以检查传递给函数的指针是否在 C 中分配了内存?
我用 C 编写了自己的函数,它接受一个字符指针 -但是[指向缓冲区]和 size-大小[缓冲区大小]。实际上,在调用这个函数之前,用户必须创建一个缓冲区并分配 buf _ siz 的内存。
Since there is a chance that user might forget to do memory allocation and simply pass the pointer to my function I want to check this. So is there any way I can check in my function to see if the pointer passed is really allocated with buf_siz amount of memory .. ??
EDIT1: It seems there is no standard library to check it .. but is there any dirty hack to check it .. ??
EDIT2: I do know that my function will be used by a good C programmer ... But I want to know whether can we check or not .. if we can I would like to hear to it ..
结论: 因此不可能检查某个特定指针是否在函数中分配了内存