Results 1 to 5 of 5

Thread: [SOLVED] quint16 weirdness

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Red face [SOLVED] quint16 weirdness

    Or it's me who's finally gone bananas!

    I have this piece of (testing) code:

    Qt Code:
    1. #include <iostream>
    2. #include <stdio.h>
    3.  
    4. #include <QCoreApplication>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication app(argc, argv);
    9.  
    10. unsigned int i;
    11.  
    12. typedef struct
    13. {
    14. quint16 response_id;
    15. quint32 status_change_id;
    16. bool result_code; // true if sucessful, false otherwise
    17. quint8 reserved[3]; /* Set to 0 */
    18. } receipt_data_type;
    19.  
    20.  
    21. receipt_data_type *receipt = new receipt_data_type;
    22. receipt->response_id = 0x0812;
    23. receipt->status_change_id = 1;
    24. receipt->result_code = true;
    25. receipt->reserved[0] = 0;
    26. receipt->reserved[1] = 0;
    27. receipt->reserved[2] = 0;
    28.  
    29.  
    30. char * p = (char *) receipt;
    31. for (i=0; i < sizeof(receipt_data_type); i++) {
    32. printf("%02X\r\n", *p++);
    33. }
    34. printf("\r\nAll members of receipt (total size:%d ) \r\n", sizeof(receipt_data_type) );
    35. printf("response_id: %02X (size: %d )\r\n",receipt->response_id, sizeof(receipt->response_id) );
    36. printf("status_change_id: %02X (size: %d )\r\n",receipt->status_change_id, sizeof(receipt->status_change_id));
    37. printf("result_code: %02X (size: %d )\r\n",receipt->result_code, sizeof(receipt->result_code));
    38. printf("reserved[0]: %02X\r\n",receipt->reserved[0]);
    39. printf("reserved[1]: %02X\r\n",receipt->reserved[1]);
    40. printf("reserved[2]: %02X\r\n",receipt->reserved[2]);
    41.  
    42. delete receipt;
    43.  
    44. return 0;
    45. }
    To copy to clipboard, switch view to plain text mode 

    Expected results:
    sizeof(receipt_data_type) == 10

    Actual results:
    sizeof(receipt_data_type) == 12

    and what's the actual ouput:
    12
    08
    FFFFFFCD
    09
    these two bold bytes shouldn't be here!
    01
    00
    00
    00
    01
    00
    00
    00

    All members of receipt (total size:12 )
    response_id: 812 (size: 2 )
    status_change_id: 01 (size: 4 )
    result_code: 01 (size: 1 )
    reserved[0]: 00
    reserved[1]: 00
    reserved[2]: 00


    Now the weird thing is that if I take out the response_id from the structure it reports the correct size (8).

    What in the name of God am I missing?!

    Thanks in advance,
    Pedro Doria Meunier.
    Last edited by pdoria; 14th October 2009 at 21:10. Reason: SOLVED

Similar Threads

  1. quint16 compiling problem
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 30th November 2007, 18:08
  2. Typedef quint16 on ARM and Win32
    By sgrasic in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 16th May 2006, 22:27
  3. How to convert from QString to quint16 ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 31st March 2006, 09:00
  4. quint16 problem !!!
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 22nd March 2006, 22:35
  5. Alpha channel weirdness with QGLContext
    By renaissanz in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2006, 16:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.