Mailing List Archive


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

Re: [tlug] compilation warnings for unsigned char



>>>>> "Jim" == Jim Breen <Jim.Breen@example.com> writes:

    Jim> I hope you experts can help; I've done a lot of RTFMing but
    Jim> got nowhere.

You won't find this in TFM because it's the GCC equivalent of WMD in
Iraq.  A highly overrated threat handled by a really big mistake.  I
believe they've hired Col. North as a coverup consultant. :-)

    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.

    Jim> Now in that case, both arguments are "unsigned char", so I
    Jim> assume the warning is because strcpy's prototype says it
    Jim> should be "char".

Right.

    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>.)

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.

    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. :-)

-- 
School of Systems and Information Engineering http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
               Ask not how you can "do" free software business;
              ask what your business can "do for" free software.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links