#pragma cancel_handler

S

Steve Richter

Is there an ANSI C or GNU C equivalent to the #pragma cancel_handler
provided in IBM's ILE C compiler?

http://publib.boulder.ibm.com/infoc...om.ibm.etools.iseries.pgmgd.doc/cpprog436.htm

What #pragma cancel_handler does is provide the building blocks for try
.... finally code block in a C function.

I am researching the degree of difficulty involved in porting ILE C
code from an IBM AS400 to GNU C.

thanks,

-Steve

FTA:

Cancel handlers provide an important function by allowing you to get
control for clean-up and recovery actions when call stack entries are
ended by something other than a normal return.

On the #pragma cancel_handler directive, the name of the cancel handler
routine (a bound ILE procedure) is specified, along with a user-defined
communications area. It is through the communications area that
information is passed from the application to the handler function.
When the cancel handler function is called, it is passed a pointer to a
structure of type _CNL_Hndlr_Parms_T which is defined in the <except.h>
header file. This structure contains a pointer to the communications
area in addition to some other useful information that is passed by the
system. This additional information includes the reason why the call
was cancelled.

void CancelHandlerForReport( _CNL_Hndlr_Parms_T *cancel_info )
{
printf("In Cancel Handler for function 'Report' ...\n");
}


void CancelHandlerForMain( _CNL_Hndlr_Parms_T *cancel_info )
{
printf("In Cancel Handler for function 'main' ...\n");
}

int main( void )
{
volatile unsigned return_code; /* communications area */
#pragma cancel_handler( CancelHandlerForMain, return_code )
return_code = 0;
#pragma disable_handler
}
 
W

Walter Roberson

Is there an ANSI C or GNU C equivalent to the #pragma cancel_handler
provided in IBM's ILE C compiler?

No ANSI/ISO C equivilent; for GNU C, you'd need to ask in a gnu
newgroup.
 
L

Lew Pitcher

Steve said:
Is there an ANSI C or GNU C equivalent to the #pragma cancel_handler
provided in IBM's ILE C compiler?

http://publib.boulder.ibm.com/infoc...om.ibm.etools.iseries.pgmgd.doc/cpprog436.htm

FWIW, according to the above link, a cancel_handler is a C++ feature.

Since this is comp.lang.C, we don't know about or discuss C++ features.
There certainly won't be an ANSI C equivalent to the #pragma
cancel_handler in ILE C, because that feature is not part of the C
language at all.

When you talk to the GNU C groups, please address your question to the
C++ side of the fence.

Thanks

What #pragma cancel_handler does is provide the building blocks for try
... finally code block in a C function.

Apparently, it doesn't, since there is no such thing as a "try ...
finally" code block in C. As I said before, you want C++, not C
 
B

Ben Pfaff

Lew Pitcher said:
Apparently, it doesn't, since there is no such thing as a "try ...
finally" code block in C. As I said before, you want C++, not C

I think he wants to implement try...finally in C, actually.
 
S

Steve Richter

Lew said:
FWIW, according to the above link, a cancel_handler is a C++ feature.

Since this is comp.lang.C, we don't know about or discuss C++ features.
There certainly won't be an ANSI C equivalent to the #pragma
cancel_handler in ILE C, because that feature is not part of the C
language at all.

yeah, it does say that but I have used it in ILE C and it works as
documented. I dont follow. How does ANSI C handle exceptions? I am
reading about signal handlers in the Linux books I have but none of
them seem to deal with how to implement a try .... finally block.

-Steve
 
E

Eric Sosman

Steve Richter wrote On 11/07/06 14:51,:
yeah, it does say that but I have used it in ILE C and it works as
documented. I dont follow. How does ANSI C handle exceptions?

The same way a fish rides a bicycle.

There are no exceptions in C, hence no handling.
I am
reading about signal handlers in the Linux books I have but none of
them seem to deal with how to implement a try .... finally block.

Not surprising: C has no "try ... finally block," and signals
are not exceptions.

As others have pointed out, you are addressing your question
to the wrong newsgroup. You are asking cooks about calculus, or
mathematicians about marzipan. You may get some answers, but if
I were you I wouldn't pay them much attention -- find a forum
where the people actually know something about your topic and
won't just make wild guesses.

That forum might be comp.lang.c++, as your repeated references
to try/finally suggest you may be writing in that language (maybe
without knowing it). Or if cancel_handler is not a C++ feature
but an IBM-specific extension, maybe you should look for a forum
devoted to IBM-specific topics. If this cancel_handler thing is
as useful and pervasive as you imply, you cannot be the first
person who's tried to find a substitute for it.

But whatever it may be, it's not C.
 
C

Cla

Steve said:
yeah, it does say that but I have used it in ILE C and it works as
documented. I dont follow. How does ANSI C handle exceptions?

There are no such things, so you don't handle them at all.
I am reading about signal handlers in the Linux books I have but none of
them seem to deal with how to implement a try .... finally block.

-Steve

I know what signal handlers are, but I cannot recall anything about a
'try .... finally block'.
 
L

loic-dev

Hi Steve,
yeah, it does say that but I have used it in ILE C and it works as
documented. I dont follow. How does ANSI C handle exceptions? I am
reading about signal handlers in the Linux books I have but none of
them seem to deal with how to implement a try .... finally block.

Exception is a compiler construct that allows you to perform non local
jump with the appropriate stack unwinding. There is no exception in
ANSI C (but your compiler may have some specific extension to support
exception).

You can implement the TRY...CATCH...FINALLY construct in C, but it is
really awkward (remember seeing that in the DCE/RPC package on Linux.
It is based on sigsetjmp/siglongjmp). You can get something close to
what you want, but not exactly what you can achieve at compiler level.

Cheers,
Loic
 

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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top