comp.lang.ada
 help / color / mirror / Atom feed
* How to port exit(s) from C to Ada
@ 2002-10-11  9:39 Manuel Collado
  2002-10-16 13:20 ` Georg Bauhaus
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Manuel Collado @ 2002-10-11  9:39 UTC (permalink / raw)


We are porting some legacy code from Modula2 + C to Ada. A basic library
module contains a procedure 'Terminate(status)' that forces termination
of the main program and returns a 'status' to the calling process. It is
implemented via the 'exit(status)' C system call.

I vould like to implement it in pure Ada. So far I'm aware of

    Ada.Command_Line.Set_Exit_Status (Code : in Exit_Status);

[LRM]: If the external execution environment supports returning an exit
status from a program, then Set_Exit_Status sets Code as the status.
Normal termination of a program returns as the exit status the value
most recently set by Set_Exit_Status, or, if no such value has been set,
then the value Success. If a program terminates abnormally, the status
set by Set_Exit_Status is ignored, and an implementation�defined exit
status value is set.

To terminate immediately, I can raise a user-defined unhandled
exception, but it would imply an abnormal termination, so the specified
exit status would be ingnored.

Is there a way to reproduce the behaviour of the 'exit(status)' C-call
in pure Ada, without calling it as a foreign procedure?

Thanks,
-- 
To reply by e-mail, please remove the extra dot
in the given address:  m.collado -> mcollado



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to port exit(s) from C to Ada
  2002-10-11  9:39 How to port exit(s) from C to Ada Manuel Collado
@ 2002-10-16 13:20 ` Georg Bauhaus
  2002-10-16 14:02 ` Preben Randhol
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Georg Bauhaus @ 2002-10-16 13:20 UTC (permalink / raw)


Manuel Collado <m.collado@lml.ls.fi.upm.es> wrote:
: Is there a way to reproduce the behaviour of the 'exit(status)' C-call
: in pure Ada, without calling it as a foreign procedure?

A compiler may allow returning an Integer to the environment, if
your main unit is a function.
Or you could handle a user defined exception and set_exit_status.
 
-- georg



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to port exit(s) from C to Ada
  2002-10-11  9:39 How to port exit(s) from C to Ada Manuel Collado
  2002-10-16 13:20 ` Georg Bauhaus
@ 2002-10-16 14:02 ` Preben Randhol
  2002-10-16 17:45 ` Stephen Leake
  2002-10-16 18:51 ` Ted Dennison
  3 siblings, 0 replies; 5+ messages in thread
From: Preben Randhol @ 2002-10-16 14:02 UTC (permalink / raw)


Manuel Collado wrote:
> We are porting some legacy code from Modula2 + C to Ada. A basic library
> module contains a procedure 'Terminate(status)' that forces termination
> of the main program and returns a 'status' to the calling process. It is
> implemented via the 'exit(status)' C system call.
> 
> I vould like to implement it in pure Ada. So far I'm aware of
> 
>     Ada.Command_Line.Set_Exit_Status (Code : in Exit_Status);

I think GNAT has something like this. You may want to check the source
code of it.

Preben
-- 
Ada95 is good for you.
http://libre.act-europe.fr/Software_Matters/02-C_pitfalls.pdf



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to port exit(s) from C to Ada
  2002-10-11  9:39 How to port exit(s) from C to Ada Manuel Collado
  2002-10-16 13:20 ` Georg Bauhaus
  2002-10-16 14:02 ` Preben Randhol
@ 2002-10-16 17:45 ` Stephen Leake
  2002-10-16 18:51 ` Ted Dennison
  3 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2002-10-16 17:45 UTC (permalink / raw)


Manuel Collado <m.collado@lml.ls.fi.upm.es> writes:

> To terminate immediately, I can raise a user-defined unhandled
> exception, but it would imply an abnormal termination, so the specified
> exit status would be ingnored.

Catch that exception in the top level procedure, and just exit
normally.

As long as you don't have dependent tasks, that will work.

> Is there a way to reproduce the behaviour of the 'exit(status)'
> C-call in pure Ada, without calling it as a foreign procedure?

There's really nothing wrong with calling 'exit', if that's the
behaviour you actually want.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to port exit(s) from C to Ada
  2002-10-11  9:39 How to port exit(s) from C to Ada Manuel Collado
                   ` (2 preceding siblings ...)
  2002-10-16 17:45 ` Stephen Leake
@ 2002-10-16 18:51 ` Ted Dennison
  3 siblings, 0 replies; 5+ messages in thread
From: Ted Dennison @ 2002-10-16 18:51 UTC (permalink / raw)


Manuel Collado <m.collado@lml.ls.fi.upm.es> wrote in message news:<3DA69C5B.A3B8F264@lml.ls.fi.upm.es>...
> We are porting some legacy code from Modula2 + C to Ada. A basic library
> module contains a procedure 'Terminate(status)' that forces termination
> of the main program and returns a 'status' to the calling process. It is
> implemented via the 'exit(status)' C system call.
...
> To terminate immediately, I can raise a user-defined unhandled
> exception, but it would imply an abnormal termination, so the specified
> exit status would be ingnored.
> 
> Is there a way to reproduce the behaviour of the 'exit(status)' C-call
> in pure Ada, without calling it as a foreign procedure?

You could always handle the "Terminate_Program" exception in the outer
scope of the main program. That would work as long as you don't raise
the exception in elaboration code or in any code called from the
declaration section of the main routine.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-10-16 18:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-11  9:39 How to port exit(s) from C to Ada Manuel Collado
2002-10-16 13:20 ` Georg Bauhaus
2002-10-16 14:02 ` Preben Randhol
2002-10-16 17:45 ` Stephen Leake
2002-10-16 18:51 ` Ted Dennison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox