This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]