为什么 XDrawString 不接受“const char *”?
查看 X11 中 XDrawString 的声明,为什么
int XDrawString(Display *display, Drawable d, GC gc,
int x, int y, char *string, int length);
第 6 个参数是类型“char *”而不是“const char *”? 绘制字符串需要修改它吗? 我见过很多人们传递常量字符串的例子; 那不安全吗?
looking at the declaration for XDrawString from X11, it is
int XDrawString(Display *display, Drawable d, GC gc,
int x, int y, char *string, int length);
How come the 6th argument is type "char *" instead of "const char *"? Does drawing the string require modifying it? I've seen lots of examples where people pass in constant strings; is that unsafe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要么是因为该函数自
const
之前就已存在,要么是因为设计 API 的人难以跟上。Either because the function has been around since before
const
or because those who designed the API have troubles keeping up.在我的两个系统(Mac OS X v10.4.11 和带有 libx11-dev 2:1.1.5-2ubuntu1.1 的 Ubuntu)上,我的 X11 标头将其声明为
const
。 来自/usr/include/X11/Xlib.h
:并且
_Xconst
被#define
'd为const
在 X11/Xfuncproto.h 中。On both of my systems (Mac OS X v10.4.11 and Ubuntu with libx11-dev 2:1.1.5-2ubuntu1.1), my X11 headers have it declared as
const
. From/usr/include/X11/Xlib.h
:And
_Xconst
is#define
'd to beconst
inX11/Xfuncproto.h
.我从未见过任何表明 XDrawString 修改传递给它的参数的内容。 这些低级 X API 非常古老,可以追溯到 80 年代中期。 很可能当时人们在标记不断的争论时不太严格。
I've never seen anything to suggest that XDrawString modifies the argument passed to it. Those low-level X APIs are very old, dating to the mid-80s. It's very likely people were a bit less rigorous in marking constant arguments as such back then.