A Simple question

Barry L. Wallis wallis at labc.dec.com
Wed Apr 11 15:25:24 AEST 1990


In article <1881 at zipeecs.umich.edu>, yhe at zip.eecs.umich.edu (Youda He) writes...
!>Here is the sample program:
!>main()
!>{
!>  char a=255;
!>  unsigned char b = 255;
!>  printf("a=%X\n",a);
!>  printf("b=%X\n",b);
!>}
!> 
!>The result is 
!>a=FFFF
!>b=FF
!>on dos, by using zortech and mcs, char is 8 bit long, why a looks like 16bit?
!>what is the difference of char and unsigned char on printf? 
!> 
!>-- Youda

The %X specifier in printf() tells the function to interpret the argument as an
int. Since the actual value is a char it is pushed on the stack as an int. If
the value pushed is defined as a signed char (as 'a' is), the high order bit is
sign extended; otherwise the high order byte is 00.
---
Barry L. Wallis			USENET: wallis at labc.dec.com
Database Consultant		Prodigy (don't laugh): DNMX41A
U.S. DECtp Resource Center	DECUServe: EISNER::WALLIS (not on the net yet)
Los Angeles, CA			"No one voted for me, I represent myself"
---



More information about the Comp.lang.c mailing list