Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, October 2007
QByteArray dump with %02hhx format failure


Message 1 in thread

Dear community,

Here is how I would like to dump the content of a QByteArray :

for (quint32 i; i < byteArray.size(); i += 1)
{
        fprintf(fdesc, "%02hhx ", *(byteArray.data() + i));
}

The dump is done, but some couples of char are prefixed with "ff" : "9A 8e 
2c ffa2", for instance.

Could someone can explain me why?

Thanks,
Christophe 


--
 [ signature omitted ] 

Message 2 in thread

Em Wednesday 24 October 2007 14:58:55 Christophe Bismuth escreveu:
> Dear community,
>
> Here is how I would like to dump the content of a QByteArray :
>
> for (quint32 i; i < byteArray.size(); i += 1)
> {
>         fprintf(fdesc, "%02hhx ", *(byteArray.data() + i));
> }
>
> The dump is done, but some couples of char are prefixed with "ff" : "9A 8e
> 2c ffa2", for instance.
>
> Could someone can explain me why?

You're on a platform where char is signed and doesn't respect C99:

`hh'
     Specifies that the argument is a `signed char' or `unsigned char',
     as appropriate.  A `char' argument is converted to an `int' or
     `unsigned int' by the default argument promotions anyway, but the
     `h' modifier says to convert it back to a `char' again.

     This modifier was introduced in ISO C99.

Also note that C++'s latest standard is from 98, so you're not technically 
allowed to use C99 in a C++ application (you can probably get away with it, 
though).

Suggestion:
         fprintf(fdesc, "%02x ", unsigned(*(byteArray.data() + i)));

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 3 in thread

Thank you Thiago for your help!

"Thiago Macieira" <thiago.macieira@xxxxxxxxxxxxx> a écrit dans le message de 
news: 200710241542.01600.thiago.macieira@xxxxxxxxxxxxxxxx 


--
 [ signature omitted ]