Skip to content

Conversation

adamgreen
Copy link
Contributor

The following line in USBHAL_KL25Z.cpp would generate a warning in GCC
because of a potential operator precendence issue:
return((USB0->FRMNUML | (USB0->FRMNUMH << 8) & 0x07FF));

This would have been interpreted as:
return((USB0->FRMNUML | ((USB0->FRMNUMH << 8) & 0x07FF)));
since & has higher precedence than |

I switched it to be:
return((USB0->FRMNUML | (USB0->FRMNUMH << 8)) & 0x07FF);
Since it makes more sense to & with 0x7FF after having merged the lower
and upper bytes together rather than just the upper byte. It should
have resulted in the same value either way.

The following line in USBHAL_KL25Z.cpp would generate a warning in GCC
because of a potential operator precendence issue:
    return((USB0->FRMNUML | (USB0->FRMNUMH << 8) & 0x07FF));

This would have been interpreted as:
    return((USB0->FRMNUML | ((USB0->FRMNUMH << 8) & 0x07FF)));
since & has higher precedence than |

I switched it to be:
    return((USB0->FRMNUML | (USB0->FRMNUMH << 8)) & 0x07FF);
Since it makes more sense to & with 0x7FF after having merged the lower
and upper bytes together rather than just the upper byte.  It should
have resulted in the same value either way.
emilmont added a commit that referenced this pull request Aug 22, 2013
@emilmont emilmont merged commit 32fa9b2 into ARMmbed:master Aug 22, 2013
@adamgreen adamgreen deleted the usbdeviceGccWarnSilence branch August 22, 2013 08:59
@adamgreen
Copy link
Contributor Author

Thanks again!

@emilmont
Copy link
Contributor

It is good to cleanup GCC warnings, after having understood (and properly commented like you do) the implications of the change.

By the way, could you please also submit a "pull request" to share your GCC warnings setting?

Thank you,
Emilio

bridadan pushed a commit that referenced this pull request Jun 21, 2016
Fix check on UVISOR_PRESENT=1 macro
SeppoTakalo pushed a commit that referenced this pull request Nov 9, 2016
geky pushed a commit to geky/mbed that referenced this pull request Aug 25, 2018
Add support for Travis CI
linlingao added a commit to linlingao/mbed-os that referenced this pull request Jul 12, 2019
Add code to set the prescaler bit count
pan- pushed a commit to pan-/mbed that referenced this pull request May 29, 2020
pan- added a commit to pan-/mbed that referenced this pull request May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants