Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] compilation warnings for unsigned char
- Date: Thu, 06 Jul 2006 16:24:39 +1000 (EST)
- From: Jim Breen <Jim.Breen@example.com>
- Subject: Re: [tlug] compilation warnings for unsigned char
["Stephen J. Turnbull" (Re: [tlug] compilation warnings for unsigned char) writes:] >> >>>>> "Jim" == Jim Breen <Jim.Breen@example.com> writes: >> Jim> With my latest distro (FDC4) the gcc (version 4.0.2 20051125 >> Jim> (Red Hat 4.0.2-8)) spews out warnings for every strcpy, >> Jim> strcat, etc. E.g. >> >> If you have no worries about anything but char, try -Wno-conversion. >> Unfortunately, conversions of integers generally *are* dangerous, so >> you could lose bad. I don't recommend it :-(, but you know your code >> better than I do. I tried that - it made no difference. >> Jim> Putting -funsigned-char as a gcc option makes no difference. >> >> Good! The libraries you're calling were compiled with the default >> definition of char; their prototypes should not be changed. (I wonder >> how they manage this? I don't see anything obvious in <string.h>.) Hmmm. It says (in string.h): extern char *strcpy (char *__restrict __dest, __const char *__restrict __src) I assumed that __restrict was the problem. >> What might fool GCC is to change the type that you use to "char" and >> then use -funsigned-char. This would of course hose anybody whose >> compiler doesn't support -funsigned-char. You probably don't want to >> do that. Ironically that gets me back where I was 15 years ago. My Japanese- pushing code began in 1991 with a DOS dictionary program (JDIC). In that I used vanilla "char" and set the compiler (Turbo C) to treat all char as unsigned. Never a problem. When I pulled a lot of the JDIC.c code into xjdicin 1992, I found there was no global setting possible (I think -funsigned-char came later), so I made all my chars unsigned (I think the concept of a signed char is quite flakey anyway.) I may well try that. >> Jim> Can anyone suggest a solution/workaround? >> >> The following is good because you know that these functions only test >> for equality. It might be preferable to do this at a somewhat higher >> level, if you have some standard patterns of usage you could encapsulate. >> >> #ifdef PSYCHOPATHIC_GCC >> # ifdef I_TRUST_CPP >> >> #define strcat(head,tail) strcat ((char *) (head), (char *) (tail)) >> >> # else >> >> inline unsigned char * >> gcc_in_a_straitjacket_strcat (unsigned char *head, unsigned char *tail) >> { >> return (unsigned char *) strcat ((char *) head, (char *) tail); >> } >> >> #undef strcat >> #define strcat gcc_in_a_straitjacket_strcat >> >> # endif /* I_TRUST_CPP */ >> #endif /* PSYCHOPATHIC_GCC */ >> >> If there isn't an autoconf macro to test for PSYCHOPATHIC_GCC, there >> should be! I_TRUST_CPP is a developer constant, so one arm can be >> optimized away. :-) I have tried just the I_TRUST_CPP section in my .h file and it worked for strc* but I shudder to think of doing it for everything like sprintf, etc. What a stupid mess. Why for Bog's sake does the signed-ness of char matter for things like strcat and strcpy anyway? Mutter, mutter. I may well just move everything to char, set -funsigned-char and be done with it. 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) ジム・ブリーン@モナシュ大蛙触Â
- Follow-Ups:
- Re: [tlug] compilation warnings for unsigned char
- From: Stephen J. Turnbull
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] compilation warnings for unsigned char
- Next by Date: Re: [tlug] Baby Steps for Command Line Backups . . . . . . . . . . . . . . .
- Previous by thread: Re: [tlug] compilation warnings for unsigned char
- Next by thread: Re: [tlug] compilation warnings for unsigned char
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links