Seeed-Studio / Seeed_SHT35

MIT License
7 stars 7 forks source link

possible bug in CHECK_RESULT macro? #9

Closed PerennialNovice closed 2 years ago

PerennialNovice commented 2 years ago

Hi,

shouldn't this #define CHECK_RESULT(a,b) do{if(a=b)

rather be #define CHECK_RESULT(a,b) do{if(a!=b)

in Seeed_SHT35.h line 64

yilungao commented 2 years ago

https://github.com/Seeed-Studio/Seeed_SHT35/blob/6e7a48f315bb527baecb01ea95fc0ddc28723a42/Seeed_SHT35.cpp#L61-L62

The intention indeed seem to be assigning b to a instead of comparing them. Don't think this is a bug.

PerennialNovice commented 2 years ago

But what could possibly be the purpose of checking whether an assignment returns true? Wouldn't that always be the case?

yilungao commented 2 years ago

Maybe take a look at this may help? https://stackoverflow.com/questions/3122284/in-which-case-ifa-b-is-a-good-idea

PerennialNovice commented 2 years ago

Thank you!

Very happy to have learned that my assumption was wrong!

Although I still find it a confusing way to write

a=b
if(b != 0)

Seems like a shortcut that drastically reduces code readability...

But do{...}while(0) is an equally strange way to do things to me

lakshanthad commented 2 years ago

Hello,

Can this issue be closed?

Thank you.

PerennialNovice commented 2 years ago

Yes, if no one else objects...

lakshanthad commented 2 years ago

Okay. You can reopen if there are any further discussions.

Thank you.