Results 1 to 4 of 4

Thread: Typedef quint16 on ARM and Win32

  1. #1

    Default Typedef quint16 on ARM and Win32

    I am using qint type definitions in my applications, but I have a serius problems with the croosplatform compitability.

    The structure that I use:

    struct DatagramHeader
    {
    quint8 version;
    quint16 lenght;
    quint16 checkSum;
    }

    The problem is that sizeof(DatagramHeader) prints out different value (from Win32) when used on ARM.

    Why???

    Regards,
    Samo

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Typedef quint16 on ARM and Win32

    Probably the problem is not in qints, but in alignment. On normal 32-bit system that structure most likely will look like this:
    Qt Code:
    1. | version |xxxxxxxxx| length |
    2. | checksum |xxxxxxxxx|xxxxxxxxx|
    To copy to clipboard, switch view to plain text mode 
    but on x86 it can be also:
    Qt Code:
    1. | version | length | chec |
    2. | ksum |
    To copy to clipboard, switch view to plain text mode 

    If you rely on the order and position of structure elements, you should force compiler to pack the structure. If you use GCC, try:
    Qt Code:
    1. struct DatagramHeader
    2. {
    3. ...
    4. } __attribute__ ((packed));
    To copy to clipboard, switch view to plain text mode 

  3. #3

    Default Re: Typedef quint16 on ARM and Win32

    Thank you for fast reply....

    I am using this structures to create a datagram header. I add it like this:

    //Adding Header to the datagram
    //Setting up variables
    struct DatagramHeader header;
    int size=sizeof(DatagramHeader);
    //Preparing heder
    QByteArray newDatagram = QByteArray::fromRawData((char *)&header, sizeof(DatagramHeader));
    //Appending data
    newDatagram.append(datapacket.data);

    And reading from the datagram:
    //Cheching the datagram
    struct DatagramHeader* header;
    header= (DatagramHeader*) datapacket.data.constData();

    Is there a better way to do it?

    Regards,
    Samo

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Typedef quint16 on ARM and Win32

    You might try the QDataStream class.

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.