type cast in initializer
Gregory Smith
greg at utcsri.UUCP
Tue Feb 25 07:54:20 AEST 1986
>> >The values of '\377' and -1 are one and the same without a type cast.
I have lost of track of who originally said that, but it is presented as
evidence that '\377' ( or any char constant, e.g. 'x' ) is of type (int),
not of type (char). This is not evidence though, since
int x; x = 'a';
will convert 'a' to (int) if it was not already, before assigning. This
includes sign extending if that is the convention on your system. The same
applies to func('x') and case '\300':. Thus the equality between
-1 and '\377' does not mean that they are both int's. The only way to tell
is to do a sizeof('x'), which is 1 if 'x' is (char) and 2 or 4 or .. if 'x'
is int.
Having said this, I will add that char constants are in fact of type (int),
which can be verified by the above test. ( I speak for 4.2BSD).
Greg Smith
University of Toronto
More information about the Comp.lang.c
mailing list