It’s my first SO question, so please be gentle. 🙂
I’m not a programming expert. I’ve got a program I’m playing with. It came with some BMP files. I still have the BMP files, but I’m converting them to C code instead. Currently, I’m loading them thusly:
static char bits[] = {
0xff,0xff,0xff,0xff,0xff,0xab,0xaa,0x5a,0x55,0xd5,0x55,0x55,0xb5,0xaa,0xaa,
0xab,0xaa,0x5a,0x55,0xd5,0x55,0x55,0xb5,0xaa,0xaa,0xab,0xaa,0x5a,0x55,0xd5,
[blah blah blah]
0xff,0xff,0xff,0xff,0xff};
walls.pixmap = XCreateBitmapFromData(dpy,DefaultRootWindow(dpy),bits,40,40);
Each of the characters that is greater than 0x80 is generating this warning:
bitmaps.c:38: warning: overflow in implicit constant conversion
So I tried changing my definition to
static unsigned char bits[] = {
but that displays a new warning:
bitmaps.c:31: warning: pointer targets in passing argument 3 of 'XCreateBitmapFromData' differ in signedness
/usr/include/X11/Xlib.h:1607: note: expected 'const char *' but argument is of type 'unsigned char *'
Is there a way to load bitmaps that will compile without warnings? Should I just accept that warnings will always appear? Should I be doing something different since I have the raw BMP files anyway?
Thanks.
Using unsigned chars should prevent the warning.
Signed chars can not actually represent the literals (which are of type
int, notchar).In other words, you could also explicitely cast each literal:
but that seems a little bit more awkward to me