By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

#pragma cancel_handler

P: n/a
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/infoce.../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
}

Nov 7 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
In article <11*********************@m73g2000cwd.googlegroups. com>,
Steve Richter <St************@gmail.comwrote:
>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
Nov 7 '06 #2

P: n/a

Walter Roberson wrote:
In article <11*********************@m73g2000cwd.googlegroups. com>,
Steve Richter <St************@gmail.comwrote:
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

Nov 7 '06 #3

P: n/a

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/infoce.../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

Nov 7 '06 #4

P: n/a
"Lew Pitcher" <lp******@sympatico.cawrites:
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
Nov 7 '06 #5

P: n/a

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/infoce.../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

Nov 7 '06 #6

P: n/a
Cla
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/infoce.../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'.

Nov 7 '06 #7

P: n/a


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/infoce.../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.

--
Er*********@sun.com

Nov 7 '06 #8

P: n/a
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

Nov 7 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.