unreachable code?

G

Gernot Frisch

I get informed that parts of my code cannot be reached. Did I do
something wrong?

try
{
if (login(progstring) > 0)
{
return 1; // OK
}
}
catch(int) // No hardlock
{
try
{
logout(NULL); // unreachable code
}
catch(int)
{;}
g_Version = MAX_VERSION; // unreachable code
}




--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
 
V

Victor Bazarov

Gernot said:
I get informed that parts of my code cannot be reached. Did I do
something wrong?

try
{
if (login(progstring) > 0)
{
return 1; // OK
}
}
catch(int) // No hardlock
{
try
{
logout(NULL); // unreachable code
}
catch(int)
{;}
g_Version = MAX_VERSION; // unreachable code
}

Could it be that in your compiler *somehow* exception handling is
disabled? Could it be that 'login' is declared with "throw()" (as
throwing nothing)? It's not your first day here. Post more code.

V
 
G

Gernot Frisch

Could it be that in your compiler *somehow* exception handling is
disabled? Could it be that 'login' is declared with "throw()" (as
throwing nothing)? It's not your first day here. Post more code.


OK. I use VC++7.1. My compiler flags seem OK:
/Od /FD /EHsc /RTC1 /MTd /GS /c /ZI /Gd /TP

Here's the code (uncalled stuf removed)



extern "C"
{
int login( const char *);
int logout(const char *);
void lib_pexit(int);
SetFunctions(void*);
}

#define MAX_VERSION 2002
int g_Version = MAX_VERSION;

// get's called on error
void lib_pexit( int ErrorCode )
{
throw (1); // C4297 unexpected exception raised
}


int CheckFeature(const char* progstring, double version)
{
SetFunctions((void*)&lib_pexit); // register "lib_pexit" function

for (int nVersion = (int)version; nVersion<=tm.wYear+3; nVersion++)
{
g_Version = nVersion;
try
{
if (login(progstring) > 0)
{
g_Version = MAX_VERSION;
return 1; // OK
}
}
catch(int) // no hardlock
{
try
{
logout(NULL);
}
catch(int)
{;}
g_Version = MAX_VERSION; // C4702 unreachable code
}
}
g_Version = MAX_VERSION; // C4702 unreachable code
return 0;
}
 
K

klaus hoffmann

Gernot said:
OK. I use VC++7.1. My compiler flags seem OK:
/Od /FD /EHsc /RTC1 /MTd /GS /c /ZI /Gd /TP

Here's the code (uncalled stuf removed)



extern "C"
{
int login( const char *);
int logout(const char *);
void lib_pexit(int);
SetFunctions(void*);
}

#define MAX_VERSION 2002
int g_Version = MAX_VERSION;

// get's called on error
void lib_pexit( int ErrorCode )
{
throw (1); // C4297 unexpected exception raised
}

I would assume that "C" functions must not throw, so lib_pexit is not expected
to throw and CheckFeature is not prepared to catch the exception raised by a
"C"-function (->unreachable code)
hth
Klaus
 
P

pillbug

I would assume that "C" functions must not throw, so lib_pexit is not
expected to throw and CheckFeature is not prepared to catch the
exception raised by a "C"-function (->unreachable code)

/EHc extern "C" defaults to nothrow.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top