Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!ucbvax!BRL.MIL!butler From: butler@BRL.MIL ("Lee A. Butler") Newsgroups: comp.sys.sgi Subject: Re: Is this a lint bug? Message-ID: <9012142035.aa25061@WOLF.BRL.MIL> Date: 15 Dec 90 01:35:51 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 59 Based upon some early returns, I can see that I did not communicate well enough in my first posting. Allow me to attempt a more thorough description. The lines in "test.c" which have the "/* warn */" comments generate warnings from lint. I don't understand why, since in each case, a value of type "char" is what is provided. Script started on Fri Dec 14 19:58:03 1990 1 >cat test.c #include char *str = "the first character"; main() { char *loc = "hello world"; char cp[64]; (void)sprintf(cp, "%s=\"%c\"\n", str, *loc); /* warn */ (void)sprintf(cp, "%s=\"%c\"\n", str, (char)*loc); /* warn */ (void)sprintf(cp, "%s=\"%c\"\n", str, *((char *)loc)); /* warn */ (void)sprintf(cp, "%s=\"%c\"\n", str, (signed char)*loc); /* ok */ (void)sprintf(cp, "%s=\"%c\"\n", str, *((signed char*)loc)); /* ok */ (void)printf("%s", cp); return(0); } 2 >lint test.c test.c ============== Warning: (8) sprintf: (char) format, (unsigned char) arg (arg 4) Warning: (9) sprintf: (char) format, (unsigned char) arg (arg 4) Warning: (10) sprintf: (char) format, (unsigned char) arg (arg 4) 3 >exit exit script done on Fri Dec 14 19:59:06 1990 script done on Fri Dec 14 19:59:07 1990 While I am aware that on various architectures, variables of type "char" behave as either "unsigned char" or "signed char", I would expect such behavior to be consistent. I would also expect lint to be unconcerned with architecture specifics such as this. Lint should only be concerned with a variable's declared type. A variable of type "char" should be portably passed to sprintf for a "%c" format irrespective of whether the local architecture treats "char" variables as signed (implying sign extension when passed to sprintf) or unsigned (no sign extension). Furthermore, I believe that the "signed" keyword is an ANSI C construct. Thus, while the type "char" may (or may not) behave as a signed char, it is unreasonable for lint to expect me to cast all of my "char" variables as "signed char" for use with sprintf and friends. The "signed" keyword is an "available" but not "required" keyword in ANSI C programs. Lee A. Butler SLCBR-VL-V Internet: butler@brl.mil Ballistic Research Laboratory Phone: (301) 278-9200 Aberdeen Proving Grounds, MD 21005-5066