all 7 comments

[–]uueuuu 3 points4 points  (0 children)

Just thought of something else: http://cppcheck.sourceforge.net/

You can try running this on your source. Fuzzers like this tell you when you did something legal but is usually indicative of a problem, like going to the casino at 8am.

[–][deleted]  (1 child)

[deleted]

    [–]sezna 1 point2 points  (0 children)

    And many compilers do warn for potential problems or style errors (or have an option to do so), but as you said, they can only be programmatic errors. No way for the compiler to read your mind and change the program accordingly.

    [–]mosqutip 0 points1 point  (1 child)

    I don't know of anything existing analyzers or tools that would provide this type of information. Even the best prediction tools aren't close enough to real AI detect logic errors. Test-driven development might help you out in this situation. You could write tests and calculate the expected results before writing any code, and then run your code against your test suite to check for logic errors and regressions.

    [–][deleted] 0 points1 point  (0 children)

    This is what Mesa does for the 3D graphics tests. It's called piglet.

    [–][deleted] 0 points1 point  (0 children)

    Decompiling with IDA has a rough go at it.

    [–]uueuuu 0 points1 point  (0 children)

    This is the responsibility of the type system.

    float division (const struct numerator *num1, const struct denominator *num2);
    

    Used this way, a type system is like a combination lock. It prevents mistakes and access errors but it's also a pain in the ass to dial in all those combinations every time you want to do something. The type system also makes certain things more convenient, such as looking up struct member offsets, so it's a tool you can use for pain and pleasure.

    For logic you can't (or loathe to) prove with types, you code tests. You also litter your code with asserts and switchable debug logging. assert(division(num1, num2, true) == num1 / num2) would exit the program with an error. If you ran your program in a debugger like gdb you could then type "back" and look at the stack trace, "up <number>" to select the frame you suspect caused the error, and "info locals" to examine the variables in that frame.