01-22-2015 09:33 AM - last edited on 11-18-2024 10:08 AM by Content Cleaner
I'm looking at pulling an old project forward to CVI 2013, but have hit a challenge, which is documented as follows:
"In assignment, the value of the right operand is evaluated before an array indexing is performed in the left operand. Expressions such as a[i] = i++;
will evaluate differently in LabWindows/CVI 2013 when compared with previous versions."
(There is a somewhat related thread here to do with the order that function arguments are evaluated.)
This change in evaluation order is shocking to me. I assume there is some C history behind it, and I'm not going to be able to change that.
So, my question is: What is the easiest way to find all places in my code where this could affect me? I have ~75,000 lines of legacy code. Perhaps some regex magic?
Thanks,
Ian
Solved! Go to Solution.
01-23-2015 09:15 AM - edited 01-23-2015 09:16 AM
You can try to compile your code with sequence point checking. CVI compiler doesnot seems to know that.
But maybe lastest version of clang and/or gcc can help there. Be sure to compile with and without optimization, some warning messages depend on this.
( try -Wsequence-point on cmd line or something like #pragma clang diagnostic warning "-Wsequence-point" in source code)
Better but harder(i think) sollution can be to use some MISRA-C checker, they should detect this but maybe they give you too much warnings about all the unspecified and undefined behaviours.
Some list is on (section analyzers): https://www.securecoding.cert.org/confluence/display/seccode/CERT+C+Coding+Standard
I do not use any of them so i cannot reccomend one.
01-30-2015 02:17 PM
Thanks! That site also has more info on this particular issue here. It looks like there are some detection tools available, listed nearer the bottom of that page. I have other tasks taking higher priority right now, but it is good to know there is hope for a non-manual option.
--Ian
02-02-2015 03:59 AM
Hi,
I am glad to help.
I test the last version of clang (3.7 builded from SVN), and i can confirm, that it detect this "issue" as warning(and lot of other warnings too).
Also it can be seamlessly integrated to CVI IDE as external compiler, so it is easy to switch between CVI regular compiler and this one. I can write some small "guide" later, If you are interested.
02-02-2015 04:24 AM
I would be very glad to see this guide, actually.
I was hoping to have clang updated in CVI but since nobody knows if or when this will happen I'd also like to try using a newer clang as external compiler.
Thanks a lot!!
02-02-2015 03:40 PM
Thank you, OVR_CZ ! I'll echo Wolfgang here: Any tips or guidance you get a chance to write would be much appreciated.
--Ian
02-04-2015 11:59 AM - last edited on 11-18-2024 10:08 AM by Content Cleaner
I wrote something like "how-to" from my notes.
It is rather big, and my english is not so good, so i choose to publish it in wiki-like document there: https://forums.ni.com/t5/Community-Documents/How-to-build-and-integrate-lastest-clang-compiler-to-CV... feel free to comment and/or edit them.
08-24-2015 06:08 AM
CVI 2015 adds the warning flag -Wsequence-point in Common level.