suggest parentheses around '-' inside '<<' [-Wparentheses]

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the compiler trying to tell me here:

 

suggest parentheses around '-' inside '<<' [-Wparentheses]

 

Invoking: ARM/GNU C Compiler : 6.3.1
C:\Users\J.Stampfl\Documents\Atmel Studio\7.0\C21starta\C21starta\hpl\sercom\hpl_sercom.c(115,44): warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
                   | (CONF_SERCOM_##n##_USART_PMODE << SERCOM_USART_CTRLB_PMODE_Pos)                                      \
                                                    ^

 

This topic has a solution.
Last Edited: Fri. Feb 23, 2018 - 11:57 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is suggesting that you add parentheses around the '-' that is inside the '<<' expression.

   | (CONF_SERCOM_##n##_USART_PMODE << SERCOM_USART_CTRLB_PMODE_Pos)        

There some nasty preprocessor token-pasting magic going on there.

Atmel love it, but it's a nightmare for users.

 

angry

 

You'll need to look at the preprocessor output to see what that's actually expanding to - it should then be obvious where the '-' and '<<' are that the warning is referring to.

 

note that -Wparentheses is the option which would disable this warning.

 

 

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You'll need to look at the preprocessor output to see what that's actually expanding to

 

Bitwise operations  (and especially shift) are on of the areas where your "intuitive" grasp of order-of-operations can fall apart...   You can start by just adding parens in the "obvious" spots:

   | ((CONF_SERCOM_##n##_USART_PMODE) << (SERCOM_USART_CTRLB_PMODE_Pos))        

I guess it's disturbing that this seems to be in Atmel's library code... 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In hal_sercom.c:

 

fixed by putting parenthsis:                  | ((CONF_SERCOM_##n##_USART_PMODE) << SERCOM_USART_CTRLB_PMODE_Pos)

 

#define CONF_SERCOM_3_USART_PMODE CONF_SERCOM_3_USART_PARITY - 1

 

shows up when setting "even parity"

Last Edited: Sat. Feb 24, 2018 - 01:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
I guess it's disturbing that this seems to be in Atmel's library code... 

Well, it is just a warning - so we can hope that Atmel did actually get it right without the extra parentheses.

 

IMO, this stuff should never be passed to users - it should be pre-processed by Atmel, and just the fully-expanded stuff released.

 

Even Atmel's own debugger chokes on this stuff.

 

angry

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...