PDA

View Full Version : doubt with this qt's code



Gopala Krishna
24th February 2007, 12:42
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 ?


#define Q_FOREACH(variable, container) \
for (const QForeachContainerBase &_container_ = qForeachContainerNew(container); \
qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->condition(); \
++qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i) \
for (variable = *qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i; \
qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk; \
--qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk)

#endif

wysota
24th February 2007, 14:39
Because the operator casts the result to the result returned by qForeachPointer() even though it returns 0 (because of the "true" condition).