News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

warning #2235 ??

Started by Vbxler, August 11, 2009, 05:38:47 PM

Previous topic - Next topic

Vbxler

Hi,

I use this function:

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.

Bitbeisser

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

Vbxler

Thank you very much!

It's not so easy when you come from VB.  :)

Bitbeisser

Quote from: Vbxler on August 13, 2009, 03:39:06 PM
Thank you very much!
Kein Problem, gern geschehen!  ;)
QuoteIt'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