Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > unreachable code?

Reply
Thread Tools

unreachable code?

 
 
Gernot Frisch
Guest
Posts: n/a
 
      04-27-2006
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


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-27-2006
Gernot Frisch wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Gernot Frisch
Guest
Posts: n/a
 
      04-27-2006

> 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;
}









 
Reply With Quote
 
klaus hoffmann
Guest
Posts: n/a
 
      04-27-2006
Gernot Frisch wrote:
>>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
> }
>


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

 
Reply With Quote
 
pillbug
Guest
Posts: n/a
 
      04-27-2006
>
>>> 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


> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Routing issue Net Unreachable David Culliton Cisco 0 11-10-2004 08:43 PM
Re: unreachable statements Jacob Java 2 08-16-2004 03:58 PM
edonkey2000 unreachable mewthree Computer Support 2 06-16-2004 06:41 AM
Cisco Student VPN exercise problem : gen_unrfrag: fail to generate unreachable, unexpected args robert Cisco 0 06-02-2004 07:33 PM
Destination Unreachable when trying SMTP from behind a PIX 501 MyndPhlyp Cisco 12 12-16-2003 09:27 PM



Advertisments