在C中使用'const',这可能导致什么移植问题? [英] Using 'const' in C, what porting trouble might that cause?

查看:57
本文介绍了在C中使用'const',这可能导致什么移植问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C接口函数中使用'const'来注意某些char *参数不会被该函数修改.

I would like to use 'const' in C interface functions to note that certain char * arguments are not modified by the function.

在将此代码移植到各种平台时,这可能会引起什么麻烦?在C代码中对'const'的支持是否很标准?这是什么时候正式成为C标准?

What trouble might this cause in porting this code to various platforms? Is support of 'const' in C code pretty standard? When did this become officially in C standard?

推荐答案

我无法想象任何编译器都不支持 const ,因此移植应该不是问题.如果您找到这样的野兽,您可以放

I can't imagine const not being supported by any compilers, so porting should be a non-issue. If you were to find such a beast, you could just put

#define const

在公共头文件中的某个位置使所有 const 关键字消失.程序的运行时语义完全不会改变(因为您的编译器始终不支持关键字).

Somewhere in a common header file to make all of the const keywords vanish. The runtime semantics of your program won't change at all (since your compiler didn't support the keyword anyway).

这篇关于在C中使用'const',这可能导致什么移植问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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