使用 c++0x 标志编译 wxWidgets
尝试使用 gcc-4.6
从带有 c++0x
标志的源代码编译 wxWidgets-2.9.1
时。我遇到了错误
在 { } [-fpermissive] 内将“128”从“int”缩小到“char”的转换
在文件 src/gtk/dcclient.cpp
中。该错误来自以下文件:
- src/gtk/bdiag.xbm
- src
- /gtk/cdiag.xbm
- src/gtk/fdiag.xbm
- src/gtk/horiz.xbm src/gtk/verti.xbm
- src/gtk/cross.xbm
这是一个已知的错误。 http://trac.wxwidgets.org/ticket/12575 所以我按照要求做了,程序编译正常。
有两种修复
基本上,diff
文件在 dcclient.h 文件中
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 文件中的类似修复
中,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:
- src/gtk/bdiag.xbm
- src/gtk/cdiag.xbm
- src/gtk/fdiag.xbm
- src/gtk/horiz.xbm
- src/gtk/verti.xbm
- 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
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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
unsigned char
、signed char
和char
(也称为“plain char”)是三种不同的类型。unsigned char*
和char*
之间没有转换。unsigned char
,signed char
andchar
(also known as 'plain char') are three different types. There is no conversion betweenunsigned char*
andchar*
.data
的类型为unsigned char*
,但gdk_bitmap_create_from
需要一个const char*
。reinterpret_cast
正在处理符号不匹配问题。data
has typeunsigned char*
, butgdk_bitmap_create_from
expects aconst char*
.reinterpret_cast
is dealing with the signedness mismatch.