一个指针传递给一个函数作为只读用C [英] Pass a pointer to a function as read-only in C

查看:105
本文介绍了一个指针传递给一个函数作为只读用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我可以将指针传递给一个函数,因此这只是一个指针的内容的副本?
我必须要确保该功能不修改的内容。

非常感谢你。


解决方案

  

我必须要确保该功能不修改的内容


除非函数有一个常量参数,你能做的唯一的事就是明确地传递一个拷贝你的数据,可能使用创建的的memcpy

Just as the title says, can I pass a pointer to a function so it's only a copy of the pointer's contents? I have to be sure the function doesn't edit the contents.

Thank you very much.

解决方案

I have to be sure the function doesn't edit the contents

Unless the function takes a const parameter, the only thing you can do is explicitly pass it a copy of your data, perhaps created using memcpy.

这篇关于一个指针传递给一个函数作为只读用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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