Signedness of char and puts()

Eljay Love-Jensen eljay@adobe.com
Thu Apr 17 13:49:00 GMT 2008


Hi Lynx,

> How should one print the actual value of a character?

Any of these will work:

printf("Character value of %s is %d.\n", "a", 'a');
printf("Character value of %s is %d.\n", "a", 'a' & 0xFF);
printf("Character value of %s is %u.\n", "a", 'a');
printf("Character value of %s is %u.\n", "a", 'a' & 0xFF);

Remember that char and short get promoted to int as parameters.

Without the 0xFF, the character could have sign extension, if that's what
you want.  (I assumed 8-bit char.)

HTH,
--Eljay



More information about the Gcc-help mailing list