On 13/05/2015 19:20, Joe Taylor wrote:
Hi Joe,
> Fussy compilers!
The warning is because so many people don't learn the operator
precedence and associativity rules and often make mistakes with complex
expressions. They tend to apply English language rules rather than the
stricter, unambiguous and, explicit C/C++ rules. This is one reason I
prefer the tokens '!', '&&' and, '||' over the tokens 'not', 'and' and,
'or' for these logical operations. Also the other alternative operators
are just plain unintuitive, for example 'and' is logical yet 'and_eq' is
bitwise but then 'not' is logical yet 'not_eq' is also logical. The
alternative operators are a design by committee mess IMHO and the
original C operators are just fine.
>
> I give up. Would anyone like to take a crack at making the following
> warning message go away? It arises on line 1752 of mainwondow.cpp in
> the v1.6.1 branch.
>
> C:\JTSDK\src\wsjtx_exp\mainwindow.cpp: In member function 'void
> MainWindow::guiUpdate()':
> C:\JTSDK\src\wsjtx_exp\mainwindow.cpp:1752:32: warning: suggest
> parentheses around '&&' within '||' [-Wparentheses]
>
> if(m_auto and (m_pctx>0) and (m_txNext or ((m_nrx==0) and (m_ntr!=-1)))
> or (m_auto and (m_pctx==100))) {
The minimum number of parentheses without changing the meaning is:
if(m_auto and m_pctx>0 and (m_txNext or m_nrx==0 and m_ntr!=-1)
or m_auto and m_pctx==100) {
but the compiler would prefer you to write:
if((m_auto and m_pctx>0 and (m_txNext or (m_nrx==0 and m_ntr!=-1)))
or (m_auto and m_pctx==100)) {
all the above expressions are equivalent.
There is never any issue IMHO in adding extra parenthesis although
breaking complex expressions into separate statements or even functions
is probably best in the long run. Adding parenthesis around relational
operator expressions is not common practice as almost all understand
they all have higher precedence than logical operators. OTOH mixing
bitwise and relational operators is a minefield and generous helpings of
parentheses are recommended.
> -- Joe
73
Bill
G4WJS.
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
wsjt-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wsjt-devel