Pass a pointer to a function as read-only in C

后端 未结 4 373
北海茫月
北海茫月 2021-01-18 15:15

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.

<
4条回答
  •  遥遥无期
    2021-01-18 15:57

    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.

提交回复
热议问题