We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Processor STM32F4 (Cortex M4), uVision 4.54, C++ V4.1.0.894 (in C++ module), Optimization level O1:
The following construction does not recognize the code change in the memcpy function:
... long long ll= 0; // copy the upper 6 bytes of ll from the unaligned data source pbData memcpy( ((BYTE*)&ll)+2, pbData, 6); if( !ll) return; ... the following code will never be reached, as ll is not reloaded in the preceding "if( !ll)" condition. (The return statement is ALWAYS used - no code is generated for the "if( !ll)" condition).
It would be very nice, if the compiler in such a case would generate a warning "Condition without use / always true" or so (as definitely any other C/C++ compiler I know would do). (This case can be solved by replacing the "ll=0" by "*(short*)&ll= 0" - but it took me quite a time to recognized the problem - I did not expect this).
Also in this case, I would appreciate very much a warning for missing brackets:
int iStatus; #define STATUS_Bit1 0x01 #define STATUS_Bit2 0x04 if( iStatus == STATUS_Bit1 | STATUS_Bit2){ ... this code is then executed always, as the compiler seems to handle "==" and "|" with identic priority, so it translates the condition as "(iStatus == STATUS_Bit1) | STATUS_Bit2" }
Here any other C/C++ compiler I use would give two warnings: "Using ambiguous operators without brackets" and "Condition without use / always true".
Please consider to add these two warnings in some future compiler update if possible.
Yes, of course you are right, Keil compiler is great.
But anyway it is a bit disturbing that there comes not any warning if somehow code drops out completely or if conditions are completely "empty".
(I have no overview, how difficult implementation of such warnings would be - in the uVision load window you recognize empty "if statements" very easily because of the missing "code bar" on the left side - so generally I would expect that such functionality somehow already is included in the Keil software, perhaps there would be some easy way to get it done).
(I cited "Microsoft" only in response to the post before - one other uC compiler I know very well (based on GNU CC I think) definitely also gives warnings for empty "if statements").