Thread: Microsoft V6 and V10 C++ differences in integer calculations

  1. #1
    Registered User
    Join Date
    Aug 2010
    Location
    England
    Posts
    90

    Microsoft V6 and V10 C++ differences in integer calculations

    I have a large and complex heuristic algorithm code that can be compiled in V6 and V10 without a problem, except that every now and then the different versions deviate in the solution.

    All calculations are integer based.

    Debugging is possible, but will take quite some time, as there are millions of iterations before deviation occurs over about 19,000 lines of code.

    I have checked the obvious such as different int definition, and these all check out, plus compiler flags were setup to match.

    I am hoping someone has had a similar problem and can suggest an issue that would help me narrow down my debugging.

    Thanks.
    Never re-write code unless the user benefits

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Are you saying that your program produces different results in different versions? If so, it looks like an uninitialized variable to me. Does it work the same in debug/release modes? How about different optimization levels?

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    England
    Posts
    90
    I tried removing code optimisation levels. No diiference. The difference only appears occasionally, maybe 1 in 100 uses, and I cannot find a pattern to the input data that points to a problem.

    Debug mode makes no difference. I am very careful with uninitialised variables, but I cannot discount it, although I think this would cause a higher difference rate.

    My thinking is something like a*b*c behaves differently and I might have to force a*(b*c). I have an overflow protector

    rmuldiv( a,b,c) which calculates a*b/c safely by converting to longs and back again after calculation. That routine shows no deviation.

    All calculations are integer based.

    Fortunately debugging aids are not impacting on the solution, so I will get there - just trying to get there a bit quicker.
    Never re-write code unless the user benefits

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Post the smallest piece of code that reproduces the problem, and we can try to figure out what's wrong with it.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    When you have the deviation, have you determined which compiler is producing the "correct" answer? Have you tried a third compiler, one from a different vendor?


    Jim

  6. #6
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Indeed, VC6 was pre C++ standard and had code generation bugs even for straightforward C code. If there was no verification of the VC6 output it may have been producing faulty answers for all this time, and you're now getting 'correct' ones.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Can I assume that you've already found some specific input that reproduces the problem every time? Once you've got that then it should be easy to debug both at once and see when they differ.

    You can then output iteration numbers and the relevant variables to file from each one. Then afterwards you run a diff tool like WinMerge over the two files to see where they started to differ.
    Then you start both again and this time let it run up until the iteration where things differed. You step through that iteration step-by-step and examine every calculation performed.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Registered User
    Join Date
    Aug 2010
    Location
    England
    Posts
    90
    One of the problems with this type of forum is thhat the original question seems to be lost. I know how to debug - it is slow and tedious. I did accept that with my original question.

    I am asking about known issues with V10, that will help me save time by structuring my debugging accordingly to save time.

    Does anyone have any known issues tohat could be relevant.
    Never re-write code unless the user benefits

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I actually think VC6 has more issues than VC10. But to me the question should be which compiler is producing the correct, verified results. Until you know which compiler is producing the incorrect results it is will be hard to narrow the problem down. And if you find that VC6 is the actual problem you can just move on.

    Jim

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I work on a software library that does extremely long and involved calculations using integers and floating point. The ONLY way we can cope with the complexity to determine why and where something is changed is to write an enormous log file. Once you have your logging, log a run compiled with VC6 and one compiled with VC10, diff them, and you should be able to find where things start to go wrong.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  11. #11
    Registered User
    Join Date
    Aug 2010
    Location
    England
    Posts
    90
    As I have already said I know how to debug with log files several megabytes in size.

    V10 is definitely the one with the problem. When it deviates it generates no solution when one clearly exists. I think I said earlier that V1.5 and V6 produce correct and identical results.

    So far no-one has come up with anything to reduce the time spent comparing very large log files, which I have had to do many times before - although looking for a compiler difference is a first - usually it is because of a self inflicted bug introduced after a software change!

    By the way, we never had any problems with V6, when we converted from v1.5.
    Never re-write code unless the user benefits

  12. #12
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Without actually seeing the offending code, it's hard to give specific advice.

    However, the logical things to look for would be

    1) an uninitialised variable, as already mentioned. Accessing the value of an undefined variable gives undefined behaviour. With some compilers, uninitialised variables get the value zero, and some programmers intentionally or unintentionally exploit that - so their code fails when built with another compiler or version.

    2) an operation involving one or more variables of signed int type is going out of range of that int type (again, undefined behaviour)

    3) basic types of different sizes. Although operations on unsigned types wrap (i.e. modulo arithmetic) the results will be different between compilers that support different sizes of the basic types. To check that, initially at least, examine sizeof() all the basic types.

    4) using integer division or modulus with negative operands. The results are implementation defined in C++.

    5) Some other form of undefined behaviour (such as falling off the end of an array, using memory after deallocating it, etc etc). One of the "joys" of code with undefined behaviour is that it can appear to work correctly (however you defined "correctly") with one compiler (or version), but not with another. The code is still wrong, just the symptoms can change.



    I doubt the problem is with V10. Microsoft V6 compiler was rather famous both for being buggy and for non-compliance with the C++ standard, and Microsoft made a concerted effort to improve the quality in later versions. It is more likely that your code worked correctly with V6 because of a bug or non-compliance in V6 that your code accidentally exploited, and the problem was corrected in V10.

    Try turning up warning levels when compiling your code .... with both versions of the compiler. The most detailed warnings are not emitted by default but, in practice, warnings are usually an indicator of code that is not guaranteed to work with every compiler.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  13. #13
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by johnggold View Post
    As I have already said I know how to debug with log files several megabytes in size.
    No, you have not already said that, nor have you demonstrated that, and I very much doubt that is true or you would probably have solved you bug by now.

    V10 is definitely the one with the problem. When it deviates it generates no solution when one clearly exists. I think I said earlier that V1.5 and V6 produce correct and identical results.
    There is no way in hell you can claim that with any degree of certainty. The most likely explanation is that your program contains code which is technically undefined behaviour that older compilers let you get away with. Older compilers let you get away with murder, or at least a lot of stupidity. We've seen dozens of cases on that on these forums quite often. It almost always comes down to that, and every man and his dog thinks they've found a compiler error, only to be shown that their code simply had a bug. Your over confidence in your existing code is rather tiresome. Get over it.

    So far no-one has come up with anything to reduce the time spent comparing very large log files, which I have had to do many times before - although looking for a compiler difference is a first - usually it is because of a self inflicted bug introduced after a software change!
    Rubbish, I gave you a very good way of comparing large log files to find the differences in just a few seconds. And of course if it's more complicated than a straight compare then you haven't found a reliable way of reproducing the problem yet (you never answered my earlier question). Even in such a case you should be able to simply write your own tool to do the compare in say about 15 minutes.

    By the way, we never had any problems with V6, when we converted from v1.5.
    Not relevant, and not of interest.

    You seem to be expecting someone to come and and say something like "Multiplying 42 by 53 gives the wrong answer in VS2010" or some such nonsense. The truth is that there is no such bug. Until you accept that the bug was probably in the code all along or post code that proves otherwise, you're just being foolish.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  14. #14
    Registered User
    Join Date
    Aug 2010
    Location
    England
    Posts
    90
    What a load of nonsense!

    First, I have two Microsoft complier bugs confirmed by Microsoft. If you have ever tried this, there are a lot of hoops to jump through. So please don't tell me about non-existent compiler faults. Interestingly, one of the bugs was detected with the software module I am working on now.

    Your certainty is worrying. You should read Robert Graves "Broken Images" - it's only short but it does describe your approach very well.

    Second, I don't really care whether the problem is a V10 compiler bug or just an undetected feature now exposed. It is still a problem that does not occur with other versions, so it has to be V10 as the problem.

    That's why I am looking for any issues that others may have found - it helps focus debugging.

    Third, comparisons are fast - I use CompareIT - preparation of two large log files takes about 30 minutes per cycle. Then you have to look at what the differences are telling you, move the debugging, and son. Obviously the process should speed up as the code is narrowed down, but it will take a couple of days.
    Never re-write code unless the user benefits

  15. #15
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Between VC6 and 2010 a lot has changed. You left out versions 2002 (good choice), 2003, 2005 and 2008. Each had a few breaking changes, that could be remedied by setting certain compiler flags. None of those were bugs.

    For example, time_t changed size in 2005 I think. If you need time_t to be 4 bytes, you need to define _USE_32BIT_TIME_T. There will likely be more changes like that and I don't think there is a document describing changes from VC6 to 2010. You might want to read each versions breaking changes while your debug file is generated.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ calculations
    By Learner87 in forum C++ Programming
    Replies: 1
    Last Post: 04-29-2008, 08:51 AM
  2. Help with calculations
    By Taka in forum C Programming
    Replies: 14
    Last Post: 09-01-2007, 07:00 PM
  3. Calculations
    By bumfluff in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 10:01 AM
  4. Replies: 5
    Last Post: 09-19-2003, 03:47 AM
  5. differences between Borland and Microsoft
    By Visual Studio in forum C Programming
    Replies: 7
    Last Post: 12-03-2002, 04:47 AM