timur@seas.gwu.edu (The Time Traveler) (11/04/90)
I'm using Microsoft C 6.0, and I have my warnings set to level 4. I'm getting an error with this expression: strlen(s)<WIDTH where WIDTH is defined as some expression including an integer. I don't exactly understand the error I get (C4018 '<' : signed/unsigned mismatch), but it looks as if it knows that WIDTH is a signed integer and strlen() returns an unsigned, and the two don't match. The problem is that WIDTH uses an integer variable from an include file which I can't modify. So basically, WIDTH is a signed expression while strlen() is unsigned, and the compiler doesn't like it. Is there anyway I can define WIDTH as unsigned even though it uses a signed expression? #define WIDTH (COLS/3) COLS is defined as an integer in the dCURSES library. I've tried stuff like #define WIDTH (unsigned(COLS)/3) but that causes weird errors elsewhere. Thanx in advance! Timur ------------------------------------------------------------ The Time Traveler Your daddy works in porno Now that mommy's not around timur@seas.gwu.edu She used to love her heroin HE891C@GWUVM.GWU.EDU But now she's underground - Guns N' Roses
schmidt@mars.jpl.nasa.gov (Kevin Schmidt) (11/14/90)
In article <2301@sparko.gwu.edu> timur@seas.gwu.edu () writes: >I'm using Microsoft C 6.0, and I have my warnings set to level 4. I'm >getting an error with this expression: > >strlen(s)<WIDTH > >where WIDTH is defined as some expression including an integer. I don't >exactly understand the error I get (C4018 '<' : signed/unsigned mismatch), >but it looks as if it knows that WIDTH is a signed integer and strlen() >returns an unsigned, and the two don't match. The problem is that WIDTH >uses an integer variable from an include file which I can't modify. > Instead of casting the expression in the #define, cast it when you use it. i.e. strlen(s) < (unsigned)WIDTH This should fix your warning. _______________________________________________________________________________ _ ____ _ | | / / / _ \ / / | Kevin T. Schmidt | schmidt@mars.jpl.nasa.gov / / / /_/ / / / | Jet Propulsion Laboratory | schmidt@jems.jpl.nasa.gov _ / / / ____/ / / | 4800 Oak Grove Dr. | / /_/ / / / / /___ | M/S 301-355 | \____/ /_/ /______/ | Pasadena, CA 91109 |
hls@rwthbs.uucp (H.L. Stahl) (11/26/90)
In article <2301@sparko.gwu.edu> timur@seas.gwu.edu () writes: >I'm using Microsoft C 6.0, and I have my warnings set to level 4. I'm >getting an error with this expression: > >strlen(s)<WIDTH > > ... In MS-C (and ANSI C ?) the return type of "strlen" is defined as "size_t", which is defined as "unsigned int" in MS-C. But strlen(s) < (size_t)(WIDTH) should work ... | _ : Hans-Ludwig Stahl, Lehrstuhl fuer Betriebssysteme, RWTH Aachen |_|_`__ : Kopernikusstr. 16, D-5100 Aachen, ..49-(0)241-804374 | |__) : Domain: hls@informatik.rwth-aachen.de |__) : uucp: ...!{seismo,mcvax,uunet}!unido!rwthinf!hls