Comments (4)
I agree... this seems like a case of missing parentheses:
while (!readOp(ENC28J60_READ_CTRL_REG, ESTAT) & ESTAT_CLKRDY)
should be...
while (!(readOp(ENC28J60_READ_CTRL_REG, ESTAT) & ESTAT_CLKRDY))
... and I honestly prefer something more like
while (0 == (readOp(ENC28J60_READ_CTRL_REG, ESTAT) & ESTAT_CLKRDY))
from ethercard.
Thanks for reporting. I have created #402 to fix this - please can you double-check it?
I created a little test to see what the compiler thinks:
#include <stdio.h>
int main()
{
printf("!0x02 & 0x01 = ");
if (!0x02 & 0x01) {
printf("true\n");
} else {
printf("false\n");
}
return 0;
}
Using gcc (on Linux) - gcc -Wall -o test.cmd test.c
- there are no errors when compiling.
But clang knows that there is a problem:
test.c:7:8: warning: logical not is only applied to the left hand side of this bitwise operator
[-Wlogical-not-parentheses]
if (!0x02 & 0x01) {
^ ~
test.c:7:8: note: add parentheses after the '!' to evaluate the bitwise operator first
if (!0x02 & 0x01) {
^
( )
test.c:7:8: note: add parentheses around left hand side expression to silence this warning
if (!0x02 & 0x01) {
^
( )
1 warning generated.
I don't think there is a way of using clang to compile for Arduino / AVR but it would be good if there was a way of doing static code analysis to find other bugs like this.
Anyone got any suggestions?
from ethercard.
No suggestions on how to coerce GCC to spot this, sorry. The counterpoint is how impressed I am that Clang can spot it!
From my perspective, I'm happy to close, but I don't know your preferred flow, so I'll just 'comment' for now.
from ethercard.
Thanks for reporting 👍
from ethercard.
Related Issues (20)
- Several typos in README.md
- ATMega1284p not working HOT 1
- esp8266 HOT 1
- FINE ADJUSTMENTS
- Example ether.browseUrl(PSTR("/foo/"), "bar", website, my_callback); not working HOT 6
- UDP Multicast MAC not correct? HOT 5
- facing problem while using with SD card
- Concurrent requests possible?
- Custom host name while setting Static IP HOT 1
- Multicast listening HOT 1
- Rename 'master' branch to 'main'
- Reading response only 512 bytes chunk of tcpsend
- Hide response header from HTTP response
- Is there any way to use other serial port for ether.printIp()?
- UDP packet is not sent - NOT STATIC IP HOT 1
- Incorrect session id returned
- DHCP client + browse url with specific port HOT 1
- Wrong Ethernet II destination MAC address. HOT 6
- Error initializing library on Arduino Nano HOT 5
- How to handle multiple sessions?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ethercard.