Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] compilation warnings for unsigned char



Jim <jep200404@example.com> chimed in with:
>> Jim Breen wrote:
>> 
>> > ... I'd like to tidy up a squillion compilation warnings ...
>> 
>> > xjdic handles all its text in unsigned char strings. 
>> 
>> > With my latest distro (FDC4) the gcc (version 4.0.2 20051125 (Red Hat
>> > 4.0.2-8))  spews out warnings for every strcpy, strcat, etc. E.g.
>> > 
>> > xjdserver.c:228: warning: pointer targets in passing argument 1 of
>> > 'strcpy' differ in signedness
>> > xjdserver.c:228: warning: pointer targets in passing argument 2 of
>> > 'strcpy' differ in signedness
>> 
>> > Now in that case, both arguments are "unsigned char", so I assume
>> > the warning is because strcpy's prototype says it should be "char".
>> 
>> Yup. That's makes sense to me also. 
>> 
>> > Can anyone suggest a solution/workaround? 
>> 
>> Where: 
>> 
>>    unsigned char foo1;
>>    unsigned char foo2;
>> 
>> Instead of: 
>> 
>>    strcpy(foo1,foo2);
>> 
>> try: 
>> 
>>    strcpy((char)foo1,(char)foo2);
>> 
>> or even: 
>> 
>>    strcpy((signed char)foo1,(signed char)foo2);

Nah. That just gave me even more ugly warnings about converting pointers
and the like.

>> Another _completely_ disgusting hack would be: 
>> 
>>    unsigned char usfoo1;
>>    unsigned char usfoo2;
>>    #define foo1 ((signed char)usfoo1)
>>    #define foo2 ((signed char)usfoo2)
>> 
>>    strcpy(foo1,foo2);
>> 
>> which would allow you to leave the arguments unmolested, 
>> but #defined foo1 and foo2 probably would not fly as lvalues. 

Yes, very ugly.

>> Yet another disgusting hack would be unions. Something like: 
>> 
>>    typedef union {
>>       unsigned char uc;
>>       signed char sc;
>>    } euchre; 
>> 
>>    euchre usfoo1;
>>    euchre usfoo2;
>> 
>>    #define foo1 (usfoo1.sc)
>>    #define foo2 (usfoo2.sc)
>> 
>>    strcpy(foo1,foo2);

Even uglier. The trouble is I use scores of string-processing functions
and they are all blowing warnings. Grrrrr....


Jim



-- 
Jim Breen                                http://www.csse.monash.edu.au/~jwb/
Clayton School of Information Technology,               Tel: +61 3 9905 9554
Monash University, VIC 3800, Australia                  Fax: +61 3 9905 5146
(Monash Provider No. 00008C)                ジム・ブリーン@モナシュ大蛙触Â


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links