I am well aware, that there will probably not be "the one most difficult to find error in c++", but I am still interested in what other people can think of / may have already encountered.
The idea for this question arose during a discussion with a friend. We agreed, that it must be rather simple to sabotage a cpp project by delierately including errors in the source code that you submit... But the best thing we could think of was to use uninitialized variables (leading to random segmentation faults at runtime). I am sure there are better ways...?!
Wanted characteristics of the faulty code:
Still, while it must be noticeable, it should not be obvious right after the submition of the code... Well, you get the idea.
Don't worry, our considerations are purely theoretical (we do not plan to sabotage any project). We simply considered this to be a nice enough thought experiment to share with others :-)
In short:
What is the most subtle way to sabotage sourcecode that might go unnoticed in a differential commit (like git) but will ultimately prevent a release of the software?
Logical errors are more difficult to locate because they do not result in any error message. A logical error is a mistake in reasoning by the programmer, but it is not a mistake in the programming language.
When developing programs there are three types of error that can occur: syntax errors. logic errors. runtime errors.
Conclusion. There are 5 different types of errors in C programming language: Syntax error, Run Time error, Logical error, Semantic error, and Linker error. Syntax errors, linker errors, and semantic errors can be identified by the compiler during compilation.
Errors are mainly 5 types that are Syntax errors, Run-time errors, Linker errors, Logical errors, and Logical errors.
Classic:
#define if while #define else
buried in some header.
Jamming on @WhozCraig's comment, also:
#define true (!!(__LINE__ % 10))
Once every ten lines true
won't be so true
, but the compiled program's behavior will stay consistent... to change inexplicably when something changes in the sources.
Along this line:
#define for if(__LINE__ % 10) for #define NULL (!(__LINE__ % 10))
Or what about:
#define virtual
this will cause serious problems - but only when dynamic dispatch is used, which may make its detection much more problematic.
In a similar fashion:
#define dynamic_cast static_cast
// Fail early, fail often #define throw std::abort();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With