Pelles C forum

C language => Beginner questions => Topic started by: Vbxler on August 11, 2009, 05:38:47 PM

Title: warning #2235 ??
Post by: Vbxler on August 11, 2009, 05:38:47 PM
Hi,

I use this function:

Code: [Select]
HINSTANCE hinstLib;

//------------------------------------------------------
// Laden der DLL
//------------------------------------------------------
int Load_DLL(char *szDLL)
{
//laden der DLL
hinstLib = LoadLibrary(szDLL);

//wenn laden erfolgreich, dann True
if (hinstLib != NULL) return 1;
}
I can compile, but get the message: warning #2235: Not all control paths return a value.
How can I prevent that?

Thank you very much.
Title: Re: warning #2235 ??
Post by: Bitbeisser on August 11, 2009, 05:54:40 PM
Adding a return value for the case that hinstLib == NULL...

You only return a value when loading of the DLL was successful, if, not, the return value is undefined...

Ralf
Title: Re: warning #2235 ??
Post by: Vbxler on August 13, 2009, 03:39:06 PM
Thank you very much!

It's not so easy when you come from VB.  :)
Title: Re: warning #2235 ??
Post by: Bitbeisser on August 18, 2009, 07:25:39 AM
Thank you very much!
Kein Problem, gern geschehen!  ;)
Quote
It's not so easy when you come from VB.  :)
If VB is compiling this without an error, it is even worse of a compiler as commonly  assumed.

It's a very general, logical programming error, leaving the function result undefined if the DLL load wasn't successful. This should generate at least a warning in all compilers...

And then C has a bad reputation for promoting bad programming practices...  :P

Ralf