This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Signedness of char and puts()
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: <lynx dot abraxas at freenet dot de>, GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 17 Apr 2008 05:43:43 -0500
- Subject: Re: Signedness of char and puts()
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