Compile Warnings

Eric McDonald mcdonald@phy.cmich.edu
Mon May 10 23:04:00 GMT 2004


On Tue, 11 May 2004, Hans Ronne wrote:

> >Well, the code really is bogus.  It should be saying "unsigned char"
> >but instead says "char".  In practice it should be relatively
> >portable, although I don't know about its legality in a language
> >lawyer sense.
> 
> In fact, those unsigned chars were added two years ago, as part of the C++
> compatibility patches:

You mean changed from 'unsigned char' to 'char'.
We can humor both pedantic ANSI C and C++ by doing something like 
the following:

#ifdef __cplusplus
#define BMAP_BYTE char
#else
#define BMAP_BYTE unsigned char
#endif

and then use BMAP_BYTE for the type.

It turns out that Xlib will take either char or unsigned char 
arrays for this function, XCreateBitmapFromData or whatever, if my 
research last night is correct. 
So, this must mean that C does an automatic widening conversion 
from char to unsigned char. I will double-check my ANSI C 
reference from K&R to verify this. Considering how long I have 
been doing C programming, it is amazing that I have to look up 
such a piece of trivia.

> Now, if the choice is between ANSI pedantic code and C++ compatibility, I
> would probably opt for the latter.

I would opt for both. :-)

Eric



More information about the Xconq7 mailing list