Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #29007 > unrolled thread

Exceptions handling in pure C

Started by"Borneq" <borneq@antyspam.hidden.pl>
First post2012-12-07 07:50 +0100
Last post2012-12-08 10:34 -0800
Articles 20 on this page of 29 — 13 participants

Back to article view | Back to comp.lang.c


Contents

  Exceptions handling in pure C "Borneq" <borneq@antyspam.hidden.pl> - 2012-12-07 07:50 +0100
    Re: Exceptions handling in pure C Ian Collins <ian-news@hotmail.com> - 2012-12-07 20:42 +1300
      Re: Exceptions handling in pure C "Borneq" <borneq@antyspam.hidden.pl> - 2012-12-07 09:23 +0100
        Re: Exceptions handling in pure C Ian Collins <ian-news@hotmail.com> - 2012-12-07 21:41 +1300
          Re: Exceptions handling in pure C BGB <cr88192@hotmail.com> - 2012-12-07 03:10 -0600
            Re: Exceptions handling in pure C Ian Collins <ian-news@hotmail.com> - 2012-12-08 07:44 +1300
              Re: Exceptions handling in pure C BGB <cr88192@hotmail.com> - 2012-12-07 17:26 -0600
          Re: Exceptions handling in pure C "Borneq" <borneq@antyspam.hidden.pl> - 2012-12-08 11:08 +0100
            Re: Exceptions handling in pure C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-12-08 19:02 +0000
              Re: Exceptions handling in pure C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-12-08 19:22 +0000
    Re: Exceptions handling in pure C James Kuyper <jameskuyper@verizon.net> - 2012-12-07 08:06 -0500
      Re: Exceptions handling in pure C "Borneq" <borneq@antyspam.hidden.pl> - 2012-12-07 16:40 +0100
        Re: Exceptions handling in pure C James Kuyper <jameskuyper@verizon.net> - 2012-12-07 11:24 -0500
          Re: Exceptions handling in C + assembler "Borneq" <borneq@antyspam.hidden.pl> - 2012-12-07 18:02 +0100
            Re: Exceptions handling in C + assembler James Kuyper <jameskuyper@verizon.net> - 2012-12-07 12:25 -0500
            Re: Exceptions handling in C + assembler "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-12-07 09:29 -0800
              Re: Exceptions handling in C + assembler "BartC" <bc@freeuk.com> - 2012-12-08 12:46 +0000
                Re: Exceptions handling in C + assembler James Kuyper <jameskuyper@verizon.net> - 2012-12-08 09:35 -0500
                Re: Exceptions handling in C + assembler Robert Wessel <robertwessel2@yahoo.com> - 2012-12-08 12:08 -0600
                  Re: Exceptions handling in C + assembler BGB <cr88192@hotmail.com> - 2012-12-08 15:19 -0600
                Re: Exceptions handling in C + assembler Jonathan Leffler <jleffler@earthlink.net> - 2012-12-16 22:37 -0800
        Re: Exceptions handling in pure C Rosario1903 <Rosario@invalid.invalid> - 2012-12-07 21:24 +0100
    Re: Exceptions handling in pure C Keith Thompson <kst-u@mib.org> - 2012-12-07 11:07 -0800
      Re: Exceptions handling in C + assembler "Borneq" <borneq@antyspam.hidden.pl> - 2012-12-07 20:35 +0100
        Re: Exceptions handling in C + assembler James Kuyper <jameskuyper@verizon.net> - 2012-12-07 15:15 -0500
          Re: Exceptions handling in C + assembler "Borneq" <borneq@antyspam.hidden.pl> - 2012-12-08 16:49 +0100
            Re: Exceptions handling in C + assembler James Kuyper <jameskuyper@verizon.net> - 2012-12-08 11:04 -0500
            Re: Exceptions handling in C + assembler Thomas Richter <thor@math.tu-berlin.de> - 2012-12-09 15:05 +0100
    Re: Exceptions handling in pure C Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-12-08 10:34 -0800

Page 1 of 2  [1] 2  Next page →


#29007 — Exceptions handling in pure C

From"Borneq" <borneq@antyspam.hidden.pl>
Date2012-12-07 07:50 +0100
SubjectExceptions handling in pure C
Message-ID<k9s3j1$c1s$1@node1.news.atman.pl>
How can translate C++ to C code with exceptions handling? Unfortunately 
Stroustrup translator cfron has only source and not compiled, llvm command 
to translate C++ => C not works. 

[toc] | [next] | [standalone]


#29008

FromIan Collins <ian-news@hotmail.com>
Date2012-12-07 20:42 +1300
Message-ID<aidkuhFac77U1@mid.individual.net>
In reply to#29007
Borneq wrote:
> How can translate C++ to C code with exceptions handling? Unfortunately
> Stroustrup translator cfron has only source and not compiled, llvm command
> to translate C++ => C not works.

Two options:

Start from scratch.
Use Comeau http://www.comeaucomputing.com/

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#29009

From"Borneq" <borneq@antyspam.hidden.pl>
Date2012-12-07 09:23 +0100
Message-ID<k9s91e$hl3$1@node1.news.atman.pl>
In reply to#29008
Użytkownik "Ian Collins" <ian-news@hotmail.com> napisał w wiadomości 
news:aidkuhFac77U1@mid.individual.net...
> Start from scratch.

How start? I haven't information about exception handling in C

> Use Comeau http://www.comeaucomputing.com/

Online http://www.comeaucomputing.com/tryitout/ can translate to C or only 
to assembler? 

[toc] | [prev] | [next] | [standalone]


#29011

FromIan Collins <ian-news@hotmail.com>
Date2012-12-07 21:41 +1300
Message-ID<aidodaFac77U2@mid.individual.net>
In reply to#29009
Borneq wrote:
> Użytkownik "Ian Collins" <ian-news@hotmail.com> napisał w wiadomości
> news:aidkuhFac77U1@mid.individual.net...
>> Start from scratch.
>
> How start? I haven't information about exception handling in C

There isn't any, you have to rewrite the code from scratch.

>> Use Comeau http://www.comeaucomputing.com/
>
> Online http://www.comeaucomputing.com/tryitout/ can translate to C or only
> to assembler?

Neither.  You have to buy the compiler.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#29013

FromBGB <cr88192@hotmail.com>
Date2012-12-07 03:10 -0600
Message-ID<k9sbtv$ggl$1@news.albasani.net>
In reply to#29011
On 12/7/2012 2:41 AM, Ian Collins wrote:
> Borneq wrote:
>> Użytkownik "Ian Collins" <ian-news@hotmail.com> napisał w wiadomości
>> news:aidkuhFac77U1@mid.individual.net...
>>> Start from scratch.
>>
>> How start? I haven't information about exception handling in C
>
> There isn't any, you have to rewrite the code from scratch.
>

well, it is possible, either to use OS-specific mechanisms (like Win32 
SEH), or write ones' own exception-handling system (potentially 
involving linked-lists and longjmp), and rewrite any code to use this.

it is kind-of ugly, but it sort of works...


>>> Use Comeau http://www.comeaucomputing.com/
>>
>> Online http://www.comeaucomputing.com/tryitout/ can translate to C or
>> only
>> to assembler?
>
> Neither.  You have to buy the compiler.
>

[toc] | [prev] | [next] | [standalone]


#29034

FromIan Collins <ian-news@hotmail.com>
Date2012-12-08 07:44 +1300
Message-ID<aiero7Fac77U3@mid.individual.net>
In reply to#29013
BGB wrote:
> On 12/7/2012 2:41 AM, Ian Collins wrote:
>> Borneq wrote:
>>> Użytkownik "Ian Collins" <ian-news@hotmail.com> napisał w wiadomości
>>> news:aidkuhFac77U1@mid.individual.net...
>>>> Start from scratch.
>>>
>>> How start? I haven't information about exception handling in C
>>
>> There isn't any, you have to rewrite the code from scratch.
>>
>
> well, it is possible, either to use OS-specific mechanisms (like Win32
> SEH), or write ones' own exception-handling system (potentially
> involving linked-lists and longjmp), and rewrite any code to use this.
>
> it is kind-of ugly, but it sort of works...

It would also be fraught with danger.  Writing exception safe code in C 
isn't easy.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#29052

FromBGB <cr88192@hotmail.com>
Date2012-12-07 17:26 -0600
Message-ID<k9tu44$40q$1@news.albasani.net>
In reply to#29034
On 12/7/2012 12:44 PM, Ian Collins wrote:
> BGB wrote:
>> On 12/7/2012 2:41 AM, Ian Collins wrote:
>>> Borneq wrote:
>>>> Użytkownik "Ian Collins" <ian-news@hotmail.com> napisał w wiadomości
>>>> news:aidkuhFac77U1@mid.individual.net...
>>>>> Start from scratch.
>>>>
>>>> How start? I haven't information about exception handling in C
>>>
>>> There isn't any, you have to rewrite the code from scratch.
>>>
>>
>> well, it is possible, either to use OS-specific mechanisms (like Win32
>> SEH), or write ones' own exception-handling system (potentially
>> involving linked-lists and longjmp), and rewrite any code to use this.
>>
>> it is kind-of ugly, but it sort of works...
>
> It would also be fraught with danger.  Writing exception safe code in C
> isn't easy.
>

yes, but it can be done...

granted, using it is partly more about consistency though.


in my case, I have a mechanism which works in one of 2 ways:
on Win32, it hooks into SEH, and uses a special exception code;
on other targets (such as Linux), it uses TLS, linked lists, and 
longjmp, basically to implement a sort of "fake SEH".

the external interface sort of crudely implements a system vaguely like 
try/catch/finally in Java, just based around function calls (and if/else 
blocks function-calls are basically used to implement the 
try/catch/finally blocks).

granted, yes, it is kind of ugly and painful to use, and so for the most 
part I ended up sticking to using return values to indicate error status.


when it came to the choice of whether my scripting language should throw 
exceptions in C land for uncaught script exceptions, or just return an 
error status, I ended up opting for an error status (with another API 
call to optionally fetch the VM's exception object).

note that if the exception manages to unwind all the way without getting 
caught anywhere, Win32 will give the message box and terminate the 
program. IIRC, for the fake-SEH, it is rigged up to print an error 
message and call "abort()" or similar.


or such...

[toc] | [prev] | [next] | [standalone]


#29057

From"Borneq" <borneq@antyspam.hidden.pl>
Date2012-12-08 11:08 +0100
Message-ID<k9v3i3$b2u$1@node1.news.atman.pl>
In reply to#29011
Użytkownik "Ian Collins" <ian-news@hotmail.com> napisał w wiadomości 
news:aidodaFac77U2@mid.individual.net...
>> Online http://www.comeaucomputing.com/tryitout/ can translate to C or 
>> only
>> to assembler?
>
> Neither.  You have to buy the compiler.

Is problem - I need both Windows and Linux compiler, comeau sold only one, 
two compilers will be too expensive 

[toc] | [prev] | [next] | [standalone]


#29072

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2012-12-08 19:02 +0000
Message-ID<slrnkc73l9.1jc.grahn+nntp@frailea.sa.invalid>
In reply to#29057
On Sat, 2012-12-08, Borneq wrote:
> U??ytkownik "Ian Collins" <ian-news@hotmail.com> napisa?? w wiadomo??ci 
> news:aidodaFac77U2@mid.individual.net...
>>> Online http://www.comeaucomputing.com/tryitout/ can translate to C or 
>>> only
>>> to assembler?
>>
>> Neither.  You have to buy the compiler.
>
> Is problem - I need both Windows and Linux compiler, comeau sold only one, 
> two compilers will be too expensive 

Why do you want pure C, anyway?  If what you have now is C++, and you
want a typical C++ feature like exceptions, why not continue with C++?

Some people avoid C++ because the language is more complex than C, but
C code created by automatic translation from C++ (not to mention the
exception thing) will be *far worse* than either C or C++.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [next] | [standalone]


#29073

FromJorgen Grahn <grahn+nntp@snipabacken.se>
Date2012-12-08 19:22 +0000
Message-ID<slrnkc74qs.1jc.grahn+nntp@frailea.sa.invalid>
In reply to#29072
On Sat, 2012-12-08, Jorgen Grahn wrote:
> On Sat, 2012-12-08, Borneq wrote:
>> U??ytkownik "Ian Collins" <ian-news@hotmail.com> napisa?? w wiadomo??ci 
>> news:aidodaFac77U2@mid.individual.net...
>>>> Online http://www.comeaucomputing.com/tryitout/ can translate to C or 
>>>> only
>>>> to assembler?
>>>
>>> Neither.  You have to buy the compiler.
>>
>> Is problem - I need both Windows and Linux compiler, comeau sold only one, 
>> two compilers will be too expensive 
>
> Why do you want pure C, anyway? [...]

Never mind; it was explained (sort of) elsewhere in the thread.

/Jorgen

-- 
  // Jorgen Grahn <grahn@  Oo  o.   .     .
\X/     snipabacken.se>   O  o   .

[toc] | [prev] | [next] | [standalone]


#29015

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-12-07 08:06 -0500
Message-ID<k9spjv$8cb$1@dont-email.me>
In reply to#29007
On 12/07/2012 01:50 AM, Borneq wrote:
> How can translate C++ to C code with exceptions handling? Unfortunately 
> Stroustrup translator cfron has only source and not compiled, llvm command 
> to translate C++ => C not works. 

C doesn't have exception handling; it's one of the many features that
C++ added to C. You can use setjmp()/longjmp() to implement a similar
functionality, but doing so is much more complicated than having
exceptions as a built-in feature of the language. That's precisely why
Stroustrup put exceptions in C++.

One of the more important complications has to do with destructors,
another C++ feature that doesn't exist in C. In C++, objects with
automatic storage duration and class type have their destructors
automatically called when their lifetime ends, even if it ends as a
result of an exception being thrown. Furthermore, it is guaranteed that
the destructors will be called in the reverse of the order in which the
constructors were called. When you translate your code to C, you'll have
to move the clean-up code from your C++ destructors into ordinary C
functions, and you'll have to insert explicit calls to them, rather than
relying on them being called implicitly. In particular, you need to make
sure that they get called even when you call longjmp() to emulate C++
exception handling. This is going to require that you keep track, in
some manner, of the list of destructors that need to be called; given
that the corresponding setjmp() will often be in a very different
section of the code, keeping track of which destructors need to be
called is non-trivial.

Redesigning your code so it doesn't rely upon exception handling is
painful, but can result in better C code than trying to translate C++
exception handling directly.

On the other hand: if your entire program never actually handles
exceptions, then you may be able to adequately emulate exceptions simply
by replacing throw() with exit(). That's the case for the C++ code I'm
working on right now.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#29021

From"Borneq" <borneq@antyspam.hidden.pl>
Date2012-12-07 16:40 +0100
Message-ID<k9t2lc$c83$1@node1.news.atman.pl>
In reply to#29015
Użytkownik "James Kuyper" <jameskuyper@verizon.net> napisał w wiadomości 
news:k9spjv$8cb$1@dont-email.me...
> On the other hand: if your entire program never actually handles
> exceptions, then you may be able to adequately emulate exceptions simply
> by replacing throw() with exit(). That's the case for the C++ code I'm
> working on right now.

Is http://www.microsoft.com/msj/0197/Exception/Exception.aspx with code:
int main()
{
    DWORD handler = (DWORD)_except_handler;

    __asm
    {                           // Build EXCEPTION_REGISTRATION record:
        push    handler         // Address of handler function
        push    FS:[0]          // Address of previous handler
        mov     FS:[0],ESP      // Install new EXECEPTION_REGISTRATION
    }

    __asm
    {
        mov     eax,0           // Zero out EAX
        mov     [eax], 1        // Write to EAX to deliberately cause a 
fault
    }

    printf( "After writing!\n" );

    __asm
    {                           // Remove our EXECEPTION_REGISTRATION record
        mov     eax,[ESP]       // Get pointer to previous record
        mov     FS:[0], EAX     // Install previous record
        add     esp, 8          // Clean our EXECEPTION_REGISTRATION off 
stack
    }

    return 0;
}

[toc] | [prev] | [next] | [standalone]


#29023

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-12-07 11:24 -0500
Message-ID<50C21829.9090705@verizon.net>
In reply to#29021
On 12/07/2012 10:40 AM, Borneq wrote:
> Użytkownik "James Kuyper" <jameskuyper@verizon.net> napisał w wiadomości 
> news:k9spjv$8cb$1@dont-email.me...
>> On the other hand: if your entire program never actually handles
>> exceptions, then you may be able to adequately emulate exceptions simply
>> by replacing throw() with exit(). That's the case for the C++ code I'm
>> working on right now.
> 
> Is http://www.microsoft.com/msj/0197/Exception/Exception.aspx with code:
> int main()
> {
>     DWORD handler = (DWORD)_except_handler;
> 
>     __asm
>     {                           // Build EXCEPTION_REGISTRATION record:
>         push    handler         // Address of handler function
>         push    FS:[0]          // Address of previous handler
>         mov     FS:[0],ESP      // Install new EXECEPTION_REGISTRATION
>     }
> 
>     __asm
>     {
>         mov     eax,0           // Zero out EAX
>         mov     [eax], 1        // Write to EAX to deliberately cause a 
> fault
>     }
> 
>     printf( "After writing!\n" );
> 
>     __asm
>     {                           // Remove our EXECEPTION_REGISTRATION record
>         mov     eax,[ESP]       // Get pointer to previous record
>         mov     FS:[0], EAX     // Install previous record
>         add     esp, 8          // Clean our EXECEPTION_REGISTRATION off 
> stack
>     }
> 
>     return 0;
> }

Your title said "pure C". The __asm keyword is not pure C; nor is
anything that's microsoft-specific. There's nothing wrong with writing
microsoft-specific code, if you're willing to tie your code to
microsoft, but if you're willing to consider solutions of that type, you
should have changed the Subject: line accordingly, and you should have
posted your message to a forum specializing in programming for Win32.

[toc] | [prev] | [next] | [standalone]


#29025 — Re: Exceptions handling in C + assembler

From"Borneq" <borneq@antyspam.hidden.pl>
Date2012-12-07 18:02 +0100
SubjectRe: Exceptions handling in C + assembler
Message-ID<k9t7ff$h2c$1@node1.news.atman.pl>
In reply to#29023
Użytkownik "James Kuyper" <jameskuyper@verizon.net> napisał w wiadomości 
news:50C21829.9090705@verizon.net...
> On 12/07/2012 10:40 AM, Borneq wrote:
> Your title said "pure C". The __asm keyword is not pure C; nor is
> anything that's microsoft-specific. There's nothing wrong with writing
> microsoft-specific code, if you're willing to tie your code to
> microsoft, but if you're willing to consider solutions of that type, you
> should have changed the Subject: line accordingly, and you should have
> posted your message to a forum specializing in programming for Win32.

Not exactly the I expressed what I have in mind. "Pure" - I think no C++ but 
C, also assebler may be. It is interesting not only for Win32 (or Win64) but 
also for Linux. 

[toc] | [prev] | [next] | [standalone]


#29028 — Re: Exceptions handling in C + assembler

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-12-07 12:25 -0500
SubjectRe: Exceptions handling in C + assembler
Message-ID<50C2269F.4070309@verizon.net>
In reply to#29025
On 12/07/2012 12:02 PM, Borneq wrote:
> Użytkownik "James Kuyper" <jameskuyper@verizon.net> napisał w wiadomości 
> news:50C21829.9090705@verizon.net...
>> On 12/07/2012 10:40 AM, Borneq wrote:
>> Your title said "pure C". The __asm keyword is not pure C; nor is
>> anything that's microsoft-specific. There's nothing wrong with writing
>> microsoft-specific code, if you're willing to tie your code to
>> microsoft, but if you're willing to consider solutions of that type, you
>> should have changed the Subject: line accordingly, and you should have
>> posted your message to a forum specializing in programming for Win32.
> 
> Not exactly the I expressed what I have in mind. "Pure" - I think no C++ but 
> C, also assebler may be. It is interesting not only for Win32 (or Win64) but 
> also for Linux. 

Well, if it includes a assembler, you should not describe it as "pure
C". It would be more accurate to describe it as "C plus assembler".
If you're interested in a single solution that works for Linux as well
as Win32, the one you found at that Microsoft web site isn't that solution.

[toc] | [prev] | [next] | [standalone]


#29029 — Re: Exceptions handling in C + assembler

From"christian.bau" <christian.bau@cbau.wanadoo.co.uk>
Date2012-12-07 09:29 -0800
SubjectRe: Exceptions handling in C + assembler
Message-ID<71d8f792-698f-4740-9841-4a587eb00f91@u19g2000yqj.googlegroups.com>
In reply to#29025
There are situations where it doesn't make sense to say "how do I do
this C++ thing in C"; the proper answer would be "just do it in C++".
Exception handling is one of those things.

When an exception is thrown, you have to clean up resources as the
exception winds its way through the call chain. In Java or C++ there
are things in the language that do this clean up automatically.
Without that, it is impossible for a mere human to always do that
cleanup correctly. Forget it.

[toc] | [prev] | [next] | [standalone]


#29059 — Re: Exceptions handling in C + assembler

From"BartC" <bc@freeuk.com>
Date2012-12-08 12:46 +0000
SubjectRe: Exceptions handling in C + assembler
Message-ID<9FGws.826493$EF4.183573@fx23.am4>
In reply to#29029

"christian.bau" <christian.bau@cbau.wanadoo.co.uk> wrote in message 
news:71d8f792-698f-4740-9841-4a587eb00f91@u19g2000yqj.googlegroups.com...
> There are situations where it doesn't make sense to say "how do I do
> this C++ thing in C"; the proper answer would be "just do it in C++".
> Exception handling is one of those things.

Yet C++ was originally implemented in C?

> When an exception is thrown, you have to clean up resources as the
> exception winds its way through the call chain.

What sort of resources need to be cleaned up?

Local objects that would have been deallocated on a normal return are 
understood. But what about more global/more persistent changes, where it's 
not clear what the intentions of the intermediate function would have been?

> In Java or C++ there
> are things in the language that do this clean up automatically.
> Without that, it is impossible for a mere human to always do that
> cleanup correctly. Forget it.

It sounds like this C code will be created automatically, so there is plenty 
of scope to add in all this capability, especially if performance isn't 
important.

-- 
Bartc 

[toc] | [prev] | [next] | [standalone]


#29062 — Re: Exceptions handling in C + assembler

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-12-08 09:35 -0500
SubjectRe: Exceptions handling in C + assembler
Message-ID<k9vj7d$fu2$1@dont-email.me>
In reply to#29059
On 12/08/2012 07:46 AM, BartC wrote:
> 
> 
> "christian.bau" <christian.bau@cbau.wanadoo.co.uk> wrote in message 
> news:71d8f792-698f-4740-9841-4a587eb00f91@u19g2000yqj.googlegroups.com...
...
>> When an exception is thrown, you have to clean up resources as the
>> exception winds its way through the call chain.
> 
> What sort of resources need to be cleaned up?

The resources, if any, associated with objects with automatic storage
duration whose lifetime is ended by the throwing of the exception, or
which are released in catch{} blocks that match the thrown exception.

> Local objects that would have been deallocated on a normal return are 
> understood. But what about more global/more persistent changes, where it's 
> not clear what the intentions of the intermediate function would have been?

The "intentions" of the intermediate function are, in C++, expressed in
two ways: the destructors of the objects that are local to that
function, and the code in the catch{} blocks that correspond to the
thrown exception. It's more than a little difficult to do that in C,
which has neither destructors nor catch{} blocks.
-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#29067 — Re: Exceptions handling in C + assembler

FromRobert Wessel <robertwessel2@yahoo.com>
Date2012-12-08 12:08 -0600
SubjectRe: Exceptions handling in C + assembler
Message-ID<t907c85vl2acdkicifo6563pgl12vj2c2q@4ax.com>
In reply to#29059
On Sat, 8 Dec 2012 12:46:29 -0000, "BartC" <bc@freeuk.com> wrote:

>
>
>"christian.bau" <christian.bau@cbau.wanadoo.co.uk> wrote in message 
>news:71d8f792-698f-4740-9841-4a587eb00f91@u19g2000yqj.googlegroups.com...
>> There are situations where it doesn't make sense to say "how do I do
>> this C++ thing in C"; the proper answer would be "just do it in C++".
>> Exception handling is one of those things.
>
>Yet C++ was originally implemented in C?


Cfront (Stroustrup's original C++ to C translator) was abandoned when
it became obvious that adding exceptions (which were a fairly late
addition to C++), was near impossible.  So Cfront never supported
exceptions.

[toc] | [prev] | [next] | [standalone]


#29083 — Re: Exceptions handling in C + assembler

FromBGB <cr88192@hotmail.com>
Date2012-12-08 15:19 -0600
SubjectRe: Exceptions handling in C + assembler
Message-ID<ka0b19$e47$1@news.albasani.net>
In reply to#29067
On 12/8/2012 12:08 PM, Robert Wessel wrote:
> On Sat, 8 Dec 2012 12:46:29 -0000, "BartC" <bc@freeuk.com> wrote:
>
>>
>>
>> "christian.bau" <christian.bau@cbau.wanadoo.co.uk> wrote in message
>> news:71d8f792-698f-4740-9841-4a587eb00f91@u19g2000yqj.googlegroups.com...
>>> There are situations where it doesn't make sense to say "how do I do
>>> this C++ thing in C"; the proper answer would be "just do it in C++".
>>> Exception handling is one of those things.
>>
>> Yet C++ was originally implemented in C?
>
>
> Cfront (Stroustrup's original C++ to C translator) was abandoned when
> it became obvious that adding exceptions (which were a fairly late
> addition to C++), was near impossible.  So Cfront never supported
> exceptions.
>

and, apparently no one considered doing it like something like this:

if(ehBeginTry())
{
	... do stuff ...
	ehEndTry();
}else if(ehCatch("SomeException"))
{
	... handle stuff ...
	ehEndCatch();
}else
...
}else if(ehBeginFinally())
{
	... cleanup ...
	ehEndFinally();		//continues unwinding
}


where "ehBeginTry()" would register the exception-handler, and 
"ehEndTry()" would unregister it.

the "ehBeginTry()" return value will indicate whether they are entering 
the "try" block, or handling a thrown exception.


in cases where resources need to be cleaned up, a block can be written like:
if(ehBeginTry())
{
	... do stuff ...
	ehEndTry();
}else if(ehBeginFinally())
{
	... cleanup ...
	ehEndFinally();
}



or such...

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.c


csiph-web