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. #if Q_BYTE_ORDER = Q_LITTLE_ENDIAN apparently not working
Forum Updated to NodeBB v4.3 + New Features

#if Q_BYTE_ORDER = Q_LITTLE_ENDIAN apparently not working

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.3k 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.
  • P Offline
    P Offline
    Pt_develop
    wrote on last edited by
    #1

    Following the documentation examples on the use of Q_BYTE_ORDER:

    @#if Q_BYTE_ORDER == Q_BIG_ENDIAN
    ...
    #endif@

    or

    @ #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
    ...
    #endif@

    I successfully tried

    @QString endianType;
    #if Q_BYTE_ORDER == Q_BIG_ENDIAN
    endianType="BIG ENDIAN";
    #endif@

    but when I tried

    @QString endianType;
    #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
    endianType="LITTLE ENDIAN";
    #endif@

    I got a compile error:
    expected constructor, destructor, or type conversion before "=" token

    Yet if I modify the code to

    @#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
    QString endianType="LITTLE ENDIAN";
    #endif@

    it compiles ok. While I can use this work arround I'm wondering if anyone knows the reason for this compile difference between the use of Q_LITTLE_ENDIAN and Q_BIG_ENDIAN when compared to Q_BYTE_ORDER>

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      This sounds a bit odd.
      Probably you should check for extra, hidden characters in your code.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mburr
        wrote on last edited by
        #3

        You probably have this code at global scope; the compiler may have even said so on the line just before the error message. The statement endianType="LITTLE ENDIAN"; is invalid at that point.

        Try the following instead:

        @
        void foo()
        {
        QString endianType;
        #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
        endianType="LITTLE ENDIAN";
        #endif
        }
        @

        There's no error when you use "the workaround" of QString endianType="LITTLE ENDIAN"; because initialization is permitted at global (or namespace) scope.

        Finally, there's no error when you have #if Q_BYTE_ORDER == Q_BIG_ENDIANbecause your machine isn't big-endian so the line that would cause the error never gets compiled.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Pt_develop
          wrote on last edited by
          #4

          Thanks mburr!

          I did some more testing and you pinpointed the problem exactly.

          1 Reply Last reply
          0

          • Login

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