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: printf format specifiers


> Hi,
> 
> I have the following line in one of my programs:
> 
> printf("%d\n", *string);
> 
> *string is a pointer to a string.  The above line prints out the ASCII
> decimal equivalent of the character that the pointer is pointing to.  This
> is what I was looking to accomplish.
> 
> My question is why?  Why wouldn't I need to use the %hu (unsigned short
> integer) format specifier?  When I do use the %hu, I get precisely the same
> results.  This despite the fact that %d reads an entire word and %hu reads a
> single byte.

I guess you would see a difference if you would use ascii chars above 127 as 
the one would change sign the other would not - and hu would read a short
which is 2bytes instead of 4 but I don_t see why %hu should read one byte 
only.

hofrat


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