Results 1 to 2 of 2

Thread: doubt with this qt's code

  1. #1
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default doubt with this qt's code

    When I was going through source of qt4.2 I was just pulled by the implementation of 'foreach' esp for compilers without typeof method.
    But I just couldn't understand as to why ternary operators are used when 0 could have been used directly. Am I missing something ? Can someone enlighten me ?

    Qt Code:
    1. #define Q_FOREACH(variable, container) \
    2. for (const QForeachContainerBase &_container_ = qForeachContainerNew(container); \
    3. qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->condition(); \
    4. ++qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i) \
    5. for (variable = *qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i; \
    6. qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk; \
    7. --qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk)
    8.  
    9. #endif
    To copy to clipboard, switch view to plain text mode 
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: doubt with this qt's code

    Because the operator casts the result to the result returned by qForeachPointer() even though it returns 0 (because of the "true" condition).

Similar Threads

  1. Pasting code from code tag in emacs
    By Gopala Krishna in forum General Discussion
    Replies: 0
    Last Post: 16th February 2007, 05:47
  2. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  3. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  4. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41

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.