l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
January 6: Social gathering
Next Installfest:
TBD
Latest News:
Nov. 18: Club officer elections
Page last updated:
2002 Sep 05 13:17

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] Where setjmp/longjmp went after C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] Where setjmp/longjmp went after C



"[vox-tech] Where setjmp/longjmp went after C" is a
good article. But I have to point out a possible
mistake.

I think there are risks to define macro"#define 
JB_ENDTRY  }JB_ULN}".

for example, in code: 

void b( char volatile c )
{
  int caught=0;

  printf( "entered b with c=%c\n", c );
  JB_TRY( &caught ) {
    printf( "doing f\n" );
    f( c );
    printf( "did f\n" );
    g( c );
    printf( "did g\n" );
  } JB_CATCH( EXCEP_MATHERR ) {
    printf( "caught MATHERR exception in b\n" );
    JB_RAISE( EXCEP_INVALIDARGS );
  } JB_CATCHDEFAULT {
    printf( "caught some other exception... c=%c,
caught=%d\n", c, caught );
    JB_RAISE( caught );
  } JB_ENDTRY;
  printf( "leaving b\n" );
}

It's OK. But what if there is no another exception
raised in catch block or catch-default block? See the
following code:

  JB_CATCH( EXCEP_MATHERR ) {
   printf( "caught MATHERR exception in b\n" );
    /*JB_RAISE( EXCEP_INVALIDARGS );*/ //no new
exception raised
  }

then, JB_ENDTRY will be executed after JB_CATCH block
.
So, JB_ULN will be executed twice, it is dangerous!

A possible solution to this problem is to:
(1)#define JB_ENDTRY }}
(2)#define JB_NORMAL_TERMINATE JN_ULN
(3)add "JB_NORMAL_TERMINATE" at the end of normal code
(try block).
So the code becomes:
  JB_TRY( &caught ) {
   ...
  JB_NORMAL_TERMINATE;
  } JB_CATCH( EXCEP_MATHERR ) {
  ...
  } JB_CATCHDEFAULT {
  ...
  } JB_ENDTRY;

Certainly, to eliminate the explicit statement
"JB_NORMAL_TERMINATE" in user code, we can define
macro JB_FIRST_CATCH:
#define JB_FIRST_CATCH JB_ULN;JB_CATCH

By user's explict code or by complier's implicit
translate, the final code would look like:

  JB_TRY( &caught ) {
   ...
  } JB_FIRST_CATCH( EXCEP_MATHERR ) {
  ...
  } JB_CATCH( EXCEP_... ) {
  ...
  } JB_CATCH( EXCEP_... ) {
  ...
  } JB_CATCHDEFAULT {
  ...
  } JB_ENDTRY;


__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!