Home>

Good afternoon!

There is a bug in the code below and I can't figure it out on my own. The bottom line is that there is not something that would exit the function and even "END testItow" does not reach! What if you write "wcout << L"Result= " << testItow() << endl;" which eliminates the need to specify the type of the return value, then everything works fine.

If possible, share how to catch such errors yourself, because no GetLastError and errno output anything. probably the program ends before they get there.

#include &lt;iostream&gt;#include &lt;windows.h&gt;#include &lt;windowsx.h&gt;#include &lt;stdlib.h&gt;#include &lt;stdio.h&gt;#include &lt;string&gt;#include &lt;tchar.h&gt;#include &lt;typeinfo&gt;#include &lt;errno.h&gt;#include &lt;cerrno&gt;using namespace std;
wchar_t*testItow();
int OffsetNumName= 33;
int main(){
    wcout&lt;&lt; L"START" &lt;&lt; endl;
    wchar_t*result;
    result= testItow();
    wcout&lt;&lt; L"Result= " &lt;&lt; result&lt;&lt; endl;
    wcout&lt;&lt; L"END" &lt;&lt; endl;
    return 0;
}
//And if so, then everything works:
//wcout &lt;&lt; L"Result= " &lt;&lt; testItow() &lt;&lt; endl;
wchar_t* testItow(){
    wcout&lt;&lt; L"START testItow" &lt;&lt; endl;
    wchar_t*str;
    _itow(OffsetNumName, str, 16);
    wcout&lt;&lt; L"END testItow" &lt;&lt; endl;
    returnstr;
}

Use a debugger. Why guess when you can see?

Stanislav Volodarskiy2022-01-14 09:54:35

When I used to code in assembler and use OllyDbg, are you talking about him? If yes, then I already tried to watch the assembly code compiled in a c++ exe file, to be honest, I was horrified. I did not think that there is so much garbage, and to compare it with the c++ code, you will have to try very hard and it will take more than one hour.

KoTTBarsik2022-01-14 12:29:03

I'm talking about a debugger at the C++ language level, where you can execute the program line by line, view the values ​​of variables, etc.

Stanislav Volodarskiy2022-01-14 12:42:44

For the first time I hear, I thought debuggers are only in assembler, where can I find this?

KoTTBarsik2022-01-14 12:52:09

sourceware.org/gdb

Stanislav Volodarskiy2022-01-14 14:56:39
c++