Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

#pragma cancel_handler

6 views
Skip to first unread message

Steve Richter

unread,
Nov 7, 2006, 12:21:05 PM11/7/06
to
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/infocenter/iadthelp/v6r0/index.jsp?topic=/com.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
}

Walter Roberson

unread,
Nov 7, 2006, 12:51:24 PM11/7/06
to
In article <1162920065....@m73g2000cwd.googlegroups.com>,

Steve Richter <Stephen...@gmail.com> wrote:
>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.
--
Prototypes are supertypes of their clones. -- maplesoft

Steve Richter

unread,
Nov 7, 2006, 1:07:06 PM11/7/06
to

Walter Roberson wrote:
> In article <1162920065....@m73g2000cwd.googlegroups.com>,
> Steve Richter <Stephen...@gmail.com> wrote:
> >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.

ok, thanks

Lew Pitcher

unread,
Nov 7, 2006, 2:35:48 PM11/7/06
to

Steve Richter wrote:
> 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/infocenter/iadthelp/v6r0/index.jsp?topic=/com.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

Ben Pfaff

unread,
Nov 7, 2006, 2:40:31 PM11/7/06
to
"Lew Pitcher" <lpit...@sympatico.ca> writes:

> Steve Richter wrote:
>> 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

I think he wants to implement try...finally in C, actually.
--
"The fact that there is a holy war doesn't mean that one of the sides
doesn't suck - usually both do..."
--Alexander Viro

Steve Richter

unread,
Nov 7, 2006, 2:51:48 PM11/7/06
to

Lew Pitcher wrote:
> Steve Richter wrote:
> > 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/infocenter/iadthelp/v6r0/index.jsp?topic=/com.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.

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

Cla

unread,
Nov 7, 2006, 3:14:18 PM11/7/06
to
Steve Richter wrote:
> Lew Pitcher wrote:
>
>>Steve Richter wrote:
>>
>>>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/infocenter/iadthelp/v6r0/index.jsp?topic=/com.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.
>
>
> 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'.

Eric Sosman

unread,
Nov 7, 2006, 3:12:04 PM11/7/06
to

Steve Richter wrote On 11/07/06 14:51,:


> Lew Pitcher wrote:
>
>>Steve Richter wrote:
>>
>>>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/infocenter/iadthelp/v6r0/index.jsp?topic=/com.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.
>
>
> 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.

--
Eric....@sun.com

loic...@gmx.net

unread,
Nov 7, 2006, 5:17:44 PM11/7/06
to
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

0 new messages