karl@haddock.ima.isc.com (Karl Heuer) (05/02/90)
In article <1639@tkou02.enet.dec.com> diamond@tkou02.enet.dec.com (diamond@tkovoa) writes: >In an implementation where sizeof(int)==1 (perfectly legal, as long as it's >at least 16 bits), EOF might also be a valid char value. I am not yet convinced of this; the ANS is ambiguous on this point. I understand the Committee seems to have ruled as you describe, but I'll wait until I see the exact statement. Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint
henry@utzoo.uucp (Henry Spencer) (05/03/90)
In article <1639@tkou02.enet.dec.com> diamond@tkou02.enet.dec.com (diamond@tkovoa) writes: >>(Hint: EOF has to be something that is not a valid char value.) > >False. In an implementation where sizeof(int)==1 (perfectly legal, as >long as it's at least 16 bits), EOF might also be a valid char value. I still think X3J11 should have held a competition like the POSIX one for undesirable interpretations of the standard. This would come under the "most demented" heading to my mind. :-) -- If OSI is the answer, what is | Henry Spencer at U of Toronto Zoology the question?? -Rolf Nordhagen| uunet!attcan!utzoo!henry henry@zoo.toronto.edu
harrison@necssd.NEC.COM (Mark Harrison) (05/04/90)
In article <1639@tkou02.enet.dec.com>, diamond@tkou02.enet.dec.com (diamond@tkovoa) writes: > False. In an implementation where sizeof(int)==1 (perfectly legal, as > long as it's at least 16 bits), EOF might also be a valid char value. But doesn't this conflict with K&R/1 p.42? "The real reason for using int instead of char is not related to any questions of possible sign extension. It is simply that getchar must return all possible characters (so that it can be used to read arbitrary input) and, in addition, a distinct EOF value. Thus its value *cannot* be represented as a char, but must instead be stored as an int." [emphasis on *cannot* theirs] -- Mark Harrison harrison@necssd.NEC.COM (214)518-5050 {necntc, cs.utexas.edu}!necssd!harrison standard disclaimers apply...
pjh@mccc.uucp (Pete Holsberg) (05/08/90)
In article <1990Apr30.164553.1693@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes: =In article <1990Apr27.000956.13201@mccc.uucp> pjh@mccc.uucp (Pete Holsberg) writes: =>Suppose one defines => int ch; =>and later, in the same function, begins a loop with => while((ch = getchar()) != EOF) =>Also suppose there is another function defined as => void fun(char c) =>and the first function calls it with => fun(ch); =>What is the passing mechanism that permits this to work? Does the =>function "fun" expect an int because c is a char? How does promotion =>(and demotion) work here? = =There are two cases. First case is when a prototype for fun() is visible =at the point where it is called; What do you mean by a prototype being visible at the point where fun() is called? =in that case, the expressions in the =argument lists are converted to the desired types, as if by assignment =to variables of those types, and there is no problem. So the char that fun() seems to expect is really an int??? That is, fun() picks an int off the stack and converts it to a char?? Or does the calling function convert ch to a char before it pushes the value? Thanks, Pete -- Prof. Peter J. Holsberg Mercer County Community College Voice: 609-586-4800 ext 371 Engineering Technology, Computers and Math 1200 Old Trenton Road, Trenton, NJ 08690 UUCP:...!princeton!mccc!pjh