lsalzman / enet

ENet reliable UDP networking library
MIT License
2.76k stars 672 forks source link

Overzealous parenthesis #49

Open gregoire-astruc opened 9 years ago

gregoire-astruc commented 9 years ago

During my build with clang, a few innocuous warnings popped up:

enet/peer.c:227:59: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]

   if ((((& peer -> dispatchedCommands) -> sentinel.next) == (& (& peer -> dispatchedCommands) -> sentinel)))

enet/protocol.c:92:67: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]

           if ((((& peer -> dispatchedCommands) -> sentinel.next) == (& (& peer -> dispatchedCommands) -> sentinel)))

enet/protocol.c:264:62: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]

    if ((((& peer -> sentReliableCommands) -> sentinel.next) == (& (& peer -> sentReliableCommands) -> sentinel)))

enet/protocol.c:1546:65: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]

       if ((((& peer -> sentReliableCommands) -> sentinel.next) == (& (& peer -> sentReliableCommands) -> sentinel)))

Nothing critical, but I like keeping the warnings as low as possible (if any at all) :)

bjorn commented 9 years ago

I think they're necessary for keeping readability in the face of putting spaces around the -> operator. :-P

Anyway, seems to me like you'll just want to disable that warning for enet code.

gregoire-astruc commented 9 years ago

I beg to differ, extra parens here are not the ones you think :)

if ((((& peer -> sentReliableCommands) -> sentinel.next) == (& (& peer -> sentReliableCommands) -> sentinel)))
/* is equivalent to */
if ( ((& peer -> sentReliableCommands) -> sentinel.next) == (& (& peer -> sentReliableCommands) -> sentinel) )

// This is
if ((expr)) /* vs */ if (expr)

So there's no argument about readability here :) And I like my warnings turned on :-$

bjorn commented 9 years ago

Heh, alright that's just strange. :)