472,989 Members | 3,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

parentheses in logic operands


'gcc' complains about this code:

#define TWI_MREAD ((unsigned int) 0x1 << 12)
#define TWI_IADRSZ_1_BYTE ((unsigned int) 0x1 << 8)

int write_single(int SlaveAddr, int IntAddrSize)
unsigned int mmr = SlaveAddr | IntAddrSize & ~TWI_MREAD;

write_single(0x22, TWI_IADRSZ_1_BYTE);

warning: suggest parentheses around arithmetic in operand of |

Certainly priority of '&' operation is higher then '|'. Should I put
parentheses like this:

SlaveAddr | (IntAddrSize & ~TWI_MREAD)


(SlaveAddr | IntAddrSize) & ~TWI_MREAD

It seems it has just logical meaning (and convenience of reading the code),
but result is same. Or it might have any side effects?

Thanks in advance.

With best regards, Roman Mashak. E-mail: mr*@tusur.ru
Jan 3 '08 #1
1 7117
On Jan 4, 2:32 am, "Roman Mashak" <m...@tusur.ruwrote:
It seems it has just logical meaning (and convenience of reading the code),
but result is same. Or it might have any side effects?
The result is not the same.
Consider this

(2 | 1) & 1 -1
2 | (1 & 1) -3
2 | 1 & 1 - ? # notice it's not undefined behavior
# just harder for the programmer to figure it out

And that is why gcc suggests parenthesis around.
Jan 3 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: seberino | last post by:
Tuples are defined with regards to parentheses ()'s as everyone knows. This causes confusion for 1 item tuples since (5) can be interpreted as a tuple OR as the number 5 in a mathematical...
by: August Karlstrom | last post by:
Hi, How come the modulus operator doesn't always yield non-negative values? I expect e.g. (-1) % 3 to be 2 but I get -1. If I want to decrement a cyclic variable n by k I have to write something...
by: Frederick Gotham | last post by:
If you wish to override the natural operator precedence and associativity in C, you can use parentheses: 5 * (4 - (2 + 7)) However, I was surprised to discover (by testing) yesterday that some...
by: Thelma Lubkin | last post by:
I've inherited code with SELECT statements that look like this one: SELECT tblSales.YEAR As , Count(tblSales.UNITS) As FROM INNER JOIN tblSales ON .STFID = tblSales.STFID WHERE...
by: Gary Wessle | last post by:
Hi in order to assign a value to a variable if a switch is true, can I do this switch && var=val; instead of if( switch == true ) var = val; and be safe? thanks
by: Lyn | last post by:
Can anyone explain this for me? A sub procedure can be called with or without parentheses around the arguments. By personal convention, I normally use parentheses. I am in the middle of a...
by: Helen Wheels | last post by:
Can we use parentheses in a check constraint in MS-SQL-server DDL? e.g. I'm having a problem with the following statement: ALTER TABLE . ADD CONSTRAINT CHECK (( IS NULL AND IS NULL) OR (...
by: somenath | last post by:
Hi All, I am trying to undestand "Type Conversions" from K&R book.I am not able to understand the bellow mentioned text "Conversion rules are more complicated when unsigned operands are...
by: vlsidesign | last post by:
I am not sure how to think about parentheses. It seems when they are used alongside characters it indicates a function, like addTwoNums(). But is also is used to enforce which operators and...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.