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:
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*
?
unsigned char
, signed char
and char
(also known as 'plain char') are three different types. There is no conversion between unsigned char*
and char*
.