Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!pt.cs.cmu.edu!dsl.pitt.edu!pitt!amanue!oglvee!norm From: norm@oglvee.UUCP (Norman Joseph) Newsgroups: comp.sys.ibm.pc.programmer Subject: Re: `C' type question... Message-ID: <564@oglvee.UUCP> Date: 10 Jul 90 15:12:14 GMT References: <26854@netnews.upenn.edu> Distribution: usa Organization: Oglevee Computer Systems, Connellsville, Pa Lines: 46 In <26854@netnews.upenn.edu> weisen@eniac.seas.upenn.edu (Neil Weisenfeld) writes: >Why does the following segment of code give a conversion between >integral types warning under MSC6.00? >#define ACTUAL_SPACE ' ' >void strmem(char *mem, char *str, int n) >{ > if (str && mem) > while (n--) > *mem++=(*str)?(*str++):ACTUAL_SPACE; >} >The *mem++= line gets the error. Since everything is a char, I'm not >sure what the problem is. ^^^^^^^^^^^^^^^^^^^^^^^^^^ Guess again. Everything -isn't- a char. Specifically, the character constant ' ' has as its type -int- whose value is the code for the corresponding character in the target character set (32 decimal in ASCII). I've never used MSC 6.0, but I'd assume that its warning you about the implicit conversion of this int value to the char value on the left hand side of the assignment above (*mem++). Since, by definition, the value of a character constant expression is representable as a char, so you can safely ignore the "warning". On the other hand, since ignoring compiler warning messages is a bad habit to fall into, you can cast the character constant as a char in the assignment: *mem++ = ( *str ) ? *str++ : (char)ACTUAL_SPACE; (Note: you -could- do this cast in the #define line as: #define ACTUAL_SPACE (char)' ' but there may be places in the code where ACTUAL_SPACE is used in an int context.) -- Norm Joseph // Internet: cgh!amanue!oglvee!norm@dsi.com Oglevee Computer Systems, Inc. // Uucp: {pitt,cgh}!amanue!oglvee!norm -- "Whaddya mean he had bullet holes in his mirror?" -- -- Norm Joseph // Internet: cgh!amanue!oglvee!norm@dsi.com Oglevee Computer Systems, Inc. // Uucp: {pitt,cgh}!amanue!oglvee!norm -- "Whaddya mean he had bullet holes in his mirror?" --