为什么 XDrawString 不接受“const char *”?

发布于 2024-07-25 03:29:54 字数 261 浏览 8 评论 0原文

查看 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月亮坠入山谷 2024-08-01 03:29:54

要么是因为该函数自 const 之前就已存在,要么是因为设计 API 的人难以跟上。

Either because the function has been around since before const or because those who designed the API have troubles keeping up.

酸甜透明夹心 2024-08-01 03:29:54

在我的两个系统(Mac OS X v10.4.11 和带有 libx11-dev 2:1.1.5-2ubuntu1.1 的 Ubuntu)上,我的 X11 标头将其声明为 const。 来自/usr/include/X11/Xlib.h

extern int XDrawString(
    Display*            /* display */,
    Drawable            /* d */,
    GC                  /* gc */,
    int                 /* x */,
    int                 /* y */,
    _Xconst char*       /* string */,
    int                 /* length */
);

并且_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:

extern int XDrawString(
    Display*            /* display */,
    Drawable            /* d */,
    GC                  /* gc */,
    int                 /* x */,
    int                 /* y */,
    _Xconst char*       /* string */,
    int                 /* length */
);

And _Xconst is #define'd to be const in X11/Xfuncproto.h.

清秋悲枫 2024-08-01 03:29:54

我从未见过任何表明 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文