On 11/14/2013 12:17 AM, matteo sanvito wrote:
>/
/>/  Hi ed,
/>/  I don't know about your first question, while about the second one,
/>/  try to change "&" to "&&" after "...STAT1)"
/>/
/>/  I'm glad to see that there is someone other that still uses gta02 :')
/>/
/>/  Best regards,
/>/  matte
/>/
/
Hi Matteo,

Thanks for your reply!

Could you explain a bit more why to change & for && ?

Wouldn't changing:
if(!readw(host->base + GLAMO_REG_MMC_RB_STAT1) & GLAMO_STAT1_MMC_IDLE)

to:
if(!readw(host->base + GLAMO_REG_MMC_RB_STAT1) && GLAMO_STAT1_MMC_IDLE)

Change the logic of the program?
Yes, this would change the behavior. Specifically, & is a bitwise-and operator, whereas && is a short-circuit and. I haven't actually looked at the code, but its likely that readw() returns an int or a char instead of a bool, so & is comparing this to a mask constant. If any of the '1' bits in the binary representation of the return from readw match the '1' bits in the mask it will return non-zero, which is equivalent to 'true' in c-based languages.

In the first case the "if" statement would be true if either
readw(host->base + GLAMO_REG_MMC_RB_STAT1) is false, or
GLAMO_STAT1_MMC_IDLE is true.

in the second case the "if" statement would be true if
eadw(host->base + GLAMO_REG_MMC_RB_STAT1) is false and
GLAMO_STAT1_MMC_IDLE is true.

I can't tell from the source code what the intention of the program was.
The reason the compiler gave you the warning is that it can't tell what the intent is either. It could either be "apply bitwise-not to the value returned from readw, then bitwise-and that to the mask and go into the block if the result is non-zero" or it could be "bitwise-and the return from readw() and the mask, then logical-not the result of that and go into the block if the result is true". Based on the operator precedence in C, the compiler will pick the first option, we just have to hope that that is what the original developer intended.
Thanks for your time!

Kind regards.

PS
Yes, the GTA02 is still my one and only mobile phone ;-)

-Andrew

_______________________________________________
Openmoko community mailing list
community@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/community

Reply via email to