Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What is the native endianness of my platform?

What is the native endianness of my platform?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kitfox
    wrote on last edited by
    #1

    I have a third party library that says it returns an array of data in the native endianness of my platform. Trouble is, how do I know what the native endianness of my platform is? Is there some sort of compile time flag I can check to test this?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2
           bool isBigEndian()
                   {
                   static const int i = 1;
                   static bool endian= ( (*(char*)&i) == 0 );
                   return endian;
                   }
      

      https://developer.ibm.com/articles/au-endianc/

      There are some Qt macros also:

      Q_BIG_ENDIAN
      This macro represents a value you can compare to the macro
      Q_BYTE_ORDER to determine the endian-ness of your system. 
      In a big-endian system, the most significant byte is stored at the lowest address. 
      The other bytes follow in decreasing order of significance.
      
        #if Q_BYTE_ORDER == Q_BIG_ENDIAN
        ...
        #endif
      
      See also Q_BYTE_ORDER and Q_LITTLE_ENDIAN.
      Q_BYTE_ORDER
      
      1 Reply Last reply
      5
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by
        #3

        Hi, also there's a Qt class QSysInfo that has a ByteOrder enum, query it like this:

        #include "qsysinfo.h"
        qDebug() << QSysInfo::ByteOrder;
        

        this returns 0 on big endian platforms and 1 on little endians

        1 Reply Last reply
        5

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved