tom 2007 0 Posted June 3, 2013 Report Share Posted June 3, 2013 Hello, Today I noticed some (what I think) strange behavior of the | operator: #define TEST_1 1 #define TEST_2 2 #define TEST_4 4 #define TEST_8 8 #define TEST_16 16 #define TEST_32 32 #define TEST_64 64 #define TEST_128 128 #define TEST_256 256 #define TEST_512 512 #define TEST_1024 1024 #define TEST_2048 2048 #define TEST_4096 4096 #define TEST_8192 8192 void main(){ unsigned int test; unsigned int test2; test = TEST_1 | TEST_2 | TEST_4 | TEST_8 | TEST_16 | TEST_32 | TEST_64 | TEST_128 | TEST_256 | TEST_512 | TEST_1024 | TEST_2048 | TEST_4096 | TEST_8192; test2 = TEST_1 + TEST_2 + TEST_4 + TEST_8 + TEST_16 + TEST_32 + TEST_64 + TEST_128 + TEST_256 + TEST_512 + TEST_1024 + TEST_2048 + TEST_4096 + TEST_8192; //test = 8447 //test2 = 16383 if (test == test2){ //... } } when splitting the test = TEST1 ... line to: test = TEST_1 | TEST_2 | TEST_4 | TEST_8 | TEST_16 | TEST_32; test = test | TEST_64 | TEST_128 | TEST_256 | TEST_512; test = test | TEST_1024 | TEST_2048 | TEST_4096 | TEST_8192; then test becomes equal to 16383 ... Compiler: boostc 7.12 (same problem under 7.10) Quote Link to post Share on other sites
davidb 0 Posted June 4, 2013 Report Share Posted June 4, 2013 Tom, I can also confirm that the problem exists. Replacing the defines directly with the values also fails as does various placements of parenthesis and casting to try and break up the problem. The code seems to break with your values as soon as you have more than 8 OR'ed above 256. Interestingly if you use enum {} for the values instead of your #defines your example works correctly and as a bonus the code generated is shorter too! Must be some clues there for Pavel and Dave. Regards davidb Quote Link to post Share on other sites
davidb 0 Posted June 4, 2013 Report Share Posted June 4, 2013 Mmm, another clue - If you reverse the order of your values so that the highest occurs first then the example again works. Regards davidb Quote Link to post Share on other sites
tom 2007 0 Posted June 4, 2013 Author Report Share Posted June 4, 2013 (edited) Yes I've noticed some of those things too. It took a while before I found the problem was in the compiler and not my code In the assembler it looks like this: SETF main_1_test MOVLW 0x20 MOVWF main_1_test+D'1' SETF main_1_test2 ;0x20FF = 8447 is loaded into test directly MOVLW 0x3F MOVWF main_1_test2+D'1' MOVF main_1_test2, W CPFSEQ main_1_test BRA label1 MOVF main_1_test2+D'1', W CPFSEQ main_1_test+D'1' Edited June 4, 2013 by tom 2007 Quote Link to post Share on other sites
Pavel 0 Posted June 4, 2013 Report Share Posted June 4, 2013 Fixed in 7.20RC3 that is available to download from http://www.sourceboost.com/CommonDownload.html Thanks for reporting. Regards, Pavel Quote Link to post Share on other sites
tom 2007 0 Posted June 4, 2013 Author Report Share Posted June 4, 2013 (edited) Says 7.12 on that page? Is that normal? Edit: nevermind it's updated now Edited June 4, 2013 by tom 2007 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.