I'm currently doing numerical calculations at the university using the C language.I'm having trouble
When using the same program on my PC,
There is a phenomenon that results are different when using a laboratory computer.
Also, if you put printf in a specific place,
Results that should have been different begin to match.
I have been told that the above problem occurs when I refer to a memory leak or outside the array area.
I want to look back at the program or use a debugging tool to solve it, but I'm stuck.
Tools and options used so far
● valgrind (option is --tool = memcheck --leak-check = full)
Gcc -D_GLIBCXX_DEBUG -fsanitize = address -fsanitize = leak
etc, but no error in the end
(In valgrind, it is 0 bytes except for still reachable and suppressed, so it is judged that there is no error.)
If i know any tools or options that solve the above problems, please let me know.
It may be better to put the code on it,
Because it is quite redundant, I will stop it.
Sorry for the fluffy question.
Answer # 1
I wonder if it is a UB as I did in the postscript request section.
Explanation that you may not know too much about Undefined Behavior (UB) and the surrounding C ++ terms
Standards and Processing System-cpprefjp C ++ Japanese Reference
I don't want to say that C ++ er is "legal" or "illegal", but what does it mean in the end? Mystery-Qiita
If you don't want to give up around anything that is undefined behavior,the compiler is allowed to do anything.
Specific examples are
Bookworm: Old New Thing: Undefined behavior causes time travel (although there are many others, time travel is the fastest)
Bookworm: Counterattack of a very clever compiler
It is very easy to follow undefined behavior in C/C ++
Devil from the nose: indeterminate value version-Qiita
C/C ++ should be able to calculate the absolute value of the difference safely before becoming null safe-Qiita There is no sharpness at the beginning such as
Some of the standard patterns that follow undefined behavior can be detected by maximizing compiler warnings, code analysis, etc., using UndefinedBehaviorSanitizer, etc. Often there is nothing but a lot of printf and steady trial and error.
In order to reduce this as much as possible, it is important to conduct unit tests (UnitTest) and loosely couple the code, and gradually increase the number of safe code.
There are various UnitTest frameworks and I think GoogleTest is famous, but I use iutest.
- C ++ program method to detect memory leaks
- visual c ++ - i want to avoid memory leaks when using mfc and opencv together
- Avoid memory leaks caused by context in Android
- Analysis of memory leaks caused by recursive references to PHP objects
- Detecting memory leaks with Android Studio (LeakCanary)
- Detailed memory leaks for Android performance optimization
- 10 ways to detect Python program runtime, CPU and memory usage
- Understanding memory leaks in Java and examples of workarounds
- c ++ - about the memory at the address of the structure type pointer variable
- Summary of the causes of memory leaks in Java and how to avoid them (super detailed version)
- Tomcat detection of memory leaks
- The ultimate solution to Android memory leaks (Part 2)
- Solve memory leaks due to misuse of logging module in Python
- Rough analysis of memory leaks in Python
- web server - how to check for memory leaks
- c ++ - to use after loading all file contents into memory
- c ++ - stack overflow in a dynamic multidimensional array
- c ++ - the escape sequence "\ r" does not work
- i want to replace the string that is output to standard output with c ++ later
- c ++ - i want to create a function that creates a variable
- c ++ - atcoder abc162 d problem rgb triplets
- c ++ - class and file loading
- c ++ - why you need header files and statically linked library files when building
- c ++ environment construction with vscode
- c ++ - i want to judge the conditional expression of the if statement by letters
- cannot execute c/c ++ with vscode