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


There was a list called tuxcprograming or something like that for C
programming doubts.. I am mention this because I see there are at times
some C programming doubts answered in this list which is supposed to be
a gcc list.. 

Anyway I dont care, it doesnt bother me this kind of messages.. but
maybe other do.


> In your case, "string" is a pointer to char, so *string is a char, which matches
> the first case above, so it is passed as int, so the format specifier "%d" works
> just fine.  If you use "%hu", printf() still reads an int, but converts it to
> an unsigned short.  Now either you didn't test this with negative char values,
> or your char happens to be an unsigned type; otherwise, "%hu" wouldn't have
> given the same output as "%d".
> 
> Btw, if you wanted to print it as a char value, instead of a short value, you
> should have used "%hhd" or "%hhu".
> 
> Hope this clarifies things for you,
> 
> 
> Segher
> 
> 
> 
-- 

gnupg public key at: wwwkeys.pgp.net

Attachment: signature.asc
Description: Esta parte del mensaje esta firmada digitalmente


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