使用 c++0x 标志编译 wxWidgets

发布于 2024-11-25 07:42:11 字数 1947 浏览 1 评论 0原文

尝试使用 gcc-4.6 从带有 c++0x 标志的源代码编译 wxWidgets-2.9.1 时。我遇到了错误

在 { } [-fpermissive] 内将“128”从“int”缩小到“char”的转换 在文件 src/gtk/dcclient.cpp 中。该错误来自以下文件:

  1. src/gtk/bdiag.xbm
  2. src
  3. /gtk/cdiag.xbm
  4. src/gtk/fdiag.xbm
  5. src/gtk/horiz.xbm src/gtk/verti.xbm
  6. src/gtk/cross.xbm

这是一个已知的错误。 http://trac.wxwidgets.org/ticket/12575 所以我按照要求做了,程序编译正常。

有两种修复

基本上,diff 文件在 dcclient.h 文件中

  1. hatches[i] = gdk_bitmap_create_from_data(NULL, bdiag_bits,bdiag_width,bdiag_height); 舱口[i] = gdk_bitmap_create_from_data(NULL, reinterpret_cast< const char* >(bdiag_bits), bdiag_width, bdiag_height);

    //在文件 bdiag.xbm 以及所有 *.xbm 文件中的类似修复

    中,
  2. static char bdiag_bits[] = {

    静态无符号字符 bdiag_bits[] = { 0x80、0x80、0x40、0x40、0x20、0x20、0x10、0x10、0x08、0x08、0x04、0x04、 0x02、0x02、0x01、0x01、0x80、0x80、0x40、0x40、0x20、0x20、0x10、0x10、 0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x01, 0x01};

我理解第二个修复,但我无法理解第一个。为什么我们需要进行reinterpret_cast< const char* > 函数 gdk_bitmap_create_from_data 声明如下:

typedef char   gchar;//in some other header file

GdkBitmap* gdk_bitmap_create_from_data (GdkDrawable *drawable, const gchar *data, gint width, gint height);

几行之后,在同一文件 dcclient.cpp 中,以下调用gdk_bitmap_create_from_data 不会给出任何错误。

char* data = new char[data_size];
//...
GdkPixmap* pixmap = gdk_bitmap_create_from_data(mask, data, dst_w, dst_h);

现在这里不需要类型转换。为什么我们需要对static unsigned char*进行reinterpret_cast?

While trying to compile wxWidgets-2.9.1 from source with c++0x flags using gcc-4.6. I came across an error

narrowing conversion of '128' from 'int' to 'char' inside { } [-fpermissive]
in the file src/gtk/dcclient.cpp. The error comes from the following files:

  1. src/gtk/bdiag.xbm
  2. src/gtk/cdiag.xbm
  3. src/gtk/fdiag.xbm
  4. src/gtk/horiz.xbm
  5. src/gtk/verti.xbm
  6. src/gtk/cross.xbm

This is a known bug.
http://trac.wxwidgets.org/ticket/12575
So I did as required and the program is compiling okay.

Basically, there are two kinds of fix that the diff file has

//in the file dcclient.h

  1. hatches[i] = gdk_bitmap_create_from_data(NULL, bdiag_bits, bdiag_width, bdiag_height);
    hatches[i] = gdk_bitmap_create_from_data(NULL, reinterpret_cast< const char* >(bdiag_bits), bdiag_width, bdiag_height);

    //in the file bdiag.xbm and similar fixes in all the *.xbm files

  2. static char bdiag_bits[] = {

    static unsigned char bdiag_bits[] = {
    0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04,
    0x02, 0x02, 0x01, 0x01, 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10,
    0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x01, 0x01};

I understand the second fix but I could not understand the first one. Why do we need to do a reinterpret_cast< const char* > The function gdk_bitmap_create_from_data is declared like this:

typedef char   gchar;//in some other header file

GdkBitmap* gdk_bitmap_create_from_data (GdkDrawable *drawable, const gchar *data, gint width, gint height);

while a few lines later in the same file dcclient.cpp the following call to the gdk_bitmap_create_from_data doesn't give any error.

char* data = new char[data_size];
//...
GdkPixmap* pixmap = gdk_bitmap_create_from_data(mask, data, dst_w, dst_h);

Now here no typecast is required. Why do we need to do a reinterpret_cast on static unsigned char*?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

德意的啸 2024-12-02 07:42:11

unsigned charsigned charchar(也称为“plain char”)是三种不同的类型。 unsigned char*char* 之间没有转换。

unsigned char, signed char and char (also known as 'plain char') are three different types. There is no conversion between unsigned char* and char*.

零度° 2024-12-02 07:42:11

data 的类型为 unsigned char*,但 gdk_bitmap_create_from 需要一个 const char*reinterpret_cast 正在处理符号不匹配问题。

data has type unsigned char*, but gdk_bitmap_create_from expects a const char*. reinterpret_cast is dealing with the signedness mismatch.

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