type of character constants

Alan J Rosenthal flaps at dgp.toronto.edu
Tue Mar 14 13:09:04 AEST 1989


charlie at vicorp.UUCP (Charlie Goldensher) writes:
>On the previous page (page 184, 6.6 Arithmetic conversions) K&R say:
>
>	First, any operands of type char or short are converted to
>	type int, and any of type float are converted to double.
>
>So what does it matter if a character constant is of type char or of
>type int?  If it is of type char, it will be *converted* to type int
>in any expression in which it is used...

It affects sizeof 'a', which is sizeof(int), not sizeof(char).


bill at twwells.uucp (T. William Wells) writes:
>There is a subtle difference. If 'c' is an integer constant, '\377'
>represents the value 255. If, on the other hand, it is a char
>constant, and characters sign extend, it represents -1.

Nope, it is an int constant, and if chars are 8 bits and the system is twos
complement and chars sign-extend, it is -1.
Reference: K&R II p193, second-to-last sentence of the last full paragraph.

ajr

--
"The goto statement has been the focus of much of this controversy."
	    -- Aho & Ullman, Principles of Compiler Design, A-W 1977, page 54.




More information about the Comp.lang.c mailing list