Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-131660

how many Bytes qFromLittleEndian uses?

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.8
    • Documentation
    • All

    Description

      1) You can read in doc about qFromLittleEndian and about qFromBigEndian text like this "Reads count little-endian numbers from memory"
      What means numbers? May be we should add text like "numbers means sizeof(typename T) Bytes".

      2) Let's talk about qFromLittleEndian. "Reads count little-endian numbers from memory location src and stores them in the host byte order representation at dest. On CPU architectures where the host byte order is big-endian (such as PowerPC) this will swap the byte order; otherwise it will just perform a memcpy from src to dest." I have x86-64 so I have litle-endian. So I should expect "otherwise it will just perform a memcpy from src to dest"? Is it means that in my case src and dest will be the same? In fact no:

      QByteArray arr= QByteArray::fromHex("AABB");
      quint16 val=0xFFFF;
      qFromLittleEndian<quint16>(reinterpret_cast<const void*>(&arr[0]), 1, &val);
      qDebug().noquote().nospace() << "u16;" << QString("0x"+QString("%1").arg(val, 2, 16, QChar('0')).toUpper());
      

      out:
      u16;0xBBAA

      3) What is range for qFromLittleEndian/qFromBigEndian's qsizetype count? Can I use 0? I test in my code and looks like I can use 0 (in this case qFromLittleEndian do nothing) but I am afraid of Undefined behavior...

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            javyas Jaishree Vyas
            dungeonlords Andrei Cherniaev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes