www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - bobef

reply incorrect detection of function not returning value <incorrect_member pathlink.com> writes:
In this case D compiler does not detect that function does not return
and if it comes to the end program crashes with access violation or something
like that...

long z()
{
if(1 || 2 || 3) return 0;
}
Jan 29 2005
parent reply "Walter" <newshound digitalmars.com> writes:
"incorrect detection of function not returning value"
<incorrect_member pathlink.com> wrote in message
news:cth7pe$mr7$1 digitaldaemon.com...
 In this case D compiler does not detect that function does not return
 and if it comes to the end program crashes with access violation or
something
 like that...

 long z()
 {
 if(1 || 2 || 3) return 0;
 }
The example program will never run off the end, which is why the compiler cannot reliably detect such at compile time. But construct an example that will run off the end - the program will throw an exception at runtime. This is as designed.
Jan 29 2005
next sibling parent reply bobef <bobef_member pathlink.com> writes:
This was the case.
if obj.WindowProc(...) return true program crashes
and compiler did not gave me a warning
I had few more case where I forgot to return but I dont't remeber them...
Probably the looked almost the same...

extern(Windows) LRESULT _g_WindowProc(HWND hWnd, uint uMsg, WPARAM wParam,
LPARAM lParam)
{
akWnd obj=_g_akWnd_map[hWnd];
LRESULT ret=0;
if(!obj || obj.m_handle!=hWnd || !obj.WindowProc(uMsg,wParam,lParam))
ret=DefWindowProcA(hWnd, uMsg, wParam, lParam);
}

In article <cthe2k$t0f$1 digitaldaemon.com>, Walter says...
"incorrect detection of function not returning value"
<incorrect_member pathlink.com> wrote in message
news:cth7pe$mr7$1 digitaldaemon.com...
 In this case D compiler does not detect that function does not return
 and if it comes to the end program crashes with access violation or
something
 like that...

 long z()
 {
 if(1 || 2 || 3) return 0;
 }
The example program will never run off the end, which is why the compiler cannot reliably detect such at compile time. But construct an example that will run off the end - the program will throw an exception at runtime. This is as designed.
Jan 30 2005
parent "Walter" <newshound digitalmars.com> writes:
If you run obj2asm on the .obj file, you should see the code where it throws
the exception where the return would have been.

"bobef" <bobef_member pathlink.com> wrote in message
news:ctit57$tb$1 digitaldaemon.com...
 This was the case.
 if obj.WindowProc(...) return true program crashes
 and compiler did not gave me a warning
 I had few more case where I forgot to return but I dont't remeber them...
 Probably the looked almost the same...

 extern(Windows) LRESULT _g_WindowProc(HWND hWnd, uint uMsg, WPARAM wParam,
 LPARAM lParam)
 {
 akWnd obj=_g_akWnd_map[hWnd];
 LRESULT ret=0;
 if(!obj || obj.m_handle!=hWnd || !obj.WindowProc(uMsg,wParam,lParam))
 ret=DefWindowProcA(hWnd, uMsg, wParam, lParam);
 }

 In article <cthe2k$t0f$1 digitaldaemon.com>, Walter says...
"incorrect detection of function not returning value"
<incorrect_member pathlink.com> wrote in message
news:cth7pe$mr7$1 digitaldaemon.com...
 In this case D compiler does not detect that function does not return
 and if it comes to the end program crashes with access violation or
something
 like that...

 long z()
 {
 if(1 || 2 || 3) return 0;
 }
The example program will never run off the end, which is why the compiler cannot reliably detect such at compile time. But construct an example
that
will run off the end - the program will throw an exception at runtime.
This
is as designed.
Jan 30 2005
prev sibling parent bobef <bobef_member pathlink.com> writes:
A little mistake :)

ret=DefWindowProcA(hWnd, uMsg, wParam, lParam);

should be read as return DefWindowProcA(hWnd, uMsg, wParam, lParam);
Jan 30 2005