06-22-2012 06:25 AM
Hi,
I just stumbled across http://www.ni.com/white-paper/12323/en#335358_by_Category.
Using the bit shift operator twice on the same line of code produces incorrect results.
Workaround: Separate the two bit shift operations into two separate lines of code.
Reported Version: 9.0 | Resolved Version: N/A | Added: 02/14/2012 |
Could someone please explain what kind of construct causes such an issue?
I haven't noticed any problems yet and haven't noticed or found a thread about this.
Thanks.
Solved! Go to Solution.
06-25-2012 02:04 AM
Does have anyone any information?
From quick search I found over 150 lines with multiple bit shift operators on one line in our source codes, and some of this is in macro definition.
Lot of this code has been developed originaly with CVI7.1 and near 30% of this has been recompiled by CVI2010.
I do not see any problem yet.
06-25-2012 10:13 AM
The reported scenario looks like this:
unsigned int a = 1, b = 62; unsigned long long result = 1ULL << a << b;
The problem occurrs because of the temporary variable used when doing two bit shifts in the same line. Separating this into two lines will produce the correct results:
unsigned int a = 1, b = 62; unsigned long long result = 1ULL << a; result = result << b;
06-26-2012 12:41 AM - edited 06-26-2012 12:42 AM
Thank you D Biel,
According to your message and some of my quick tests, it seems to me ,that the problem occur when shift operator is inside another shift operator(on left side) and value is 64bit number.
However, code like (1ULL << a) +(1ULL<< b) works well, which cover most of my ussage cases (of shift operator). I have similar code on only 3 places,but not with 64bit number so it is fine.
It would be nice if you can change text in known issue list with better description and/or add example so there be less panic for any reader.
06-26-2012 02:45 AM
Thanks.