comp.lang.ada
 help / color / mirror / Atom feed
* Main (function) program with exit(status)
@ 1994-09-16 15:05 John J Cupak Jr CCP
  1994-09-16 21:39 ` David Emery
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: John J Cupak Jr CCP @ 1994-09-16 15:05 UTC (permalink / raw)



In a recent code review, I saw the following code for an Ada main program 
(LOTS of real code omitted!):

	function Example return Integer is
	begin
	  return (-1); 
	end Example;

It was the intent of the developer to return a non-zero status to the
unix shell in the event of an internal error. (btw, it works!)

Most coding standards, and even the LRM, state that the main program
must be a parameterless procedure. However, it seems that there's
nothing to prevent the main program from being a parameterless function!

I suggested that the programmer insert a call to the unix exit()
function (with appropriate interface pragmas) instead.

I wrote a short test program under VAX/VMS Ada, and discovered that DCL
will trap/check the return status of an Ada main program also. However,
the status must have values according to the VMS Status Word.

Has anyone encountered/used this technique before? What do you 'netters
think on this one?

John J. Cupak, Jr., CCP       Lockheed DECNet: NHQVAX::CUPAK
Lockheed Sanders, Inc.        Internet       : cupak@rapnet.sanders.LOCKHEED.COM
95 Canal Street / MER15-2403  CompuServe     : 72411.3176@compuserve.com 
Nashua, NH 03061-0868         Telephone      : (603) 885-2142     FAX: 885-1480



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

* Re: Main (function) program with exit(status)
  1994-09-16 15:05 Main (function) program with exit(status) John J Cupak Jr CCP
@ 1994-09-16 21:39 ` David Emery
  1994-09-16 22:31 ` Bob Kitzberger
  1994-09-17  3:18 ` Robert Dewar
  2 siblings, 0 replies; 6+ messages in thread
From: David Emery @ 1994-09-16 21:39 UTC (permalink / raw)


[function returing integer as main, return value used as OS process status.]
Completely non-portable!

Incidentally, one draft of POSIX/Ada supported this, and was 'voted
down' during balloting.  A conforming implementation may support an
Ada main program being a function, but an application which uses this
is no long strictly conforming to POSIX/Ada.

				dave
--
--The preceeding opinions do not necessarily reflect the opinions of
--The MITRE Corporation or its sponsors. 
-- "A good plan violently executed -NOW- is better than a perfect plan
--  next week"                                      George Patton
-- "Any damn fool can write a plan.  It's the execution that gets you
--  all screwed up"                              James Hollingsworth
-------------------------------------------------------------------------



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

* Re: Main (function) program with exit(status)
  1994-09-16 15:05 Main (function) program with exit(status) John J Cupak Jr CCP
  1994-09-16 21:39 ` David Emery
@ 1994-09-16 22:31 ` Bob Kitzberger
  1994-09-17  3:18 ` Robert Dewar
  2 siblings, 0 replies; 6+ messages in thread
From: Bob Kitzberger @ 1994-09-16 22:31 UTC (permalink / raw)


John J Cupak Jr CCP (cupak@rapnet.sanders.lockheed.com) wrote:

: Most coding standards, and even the LRM, state that the main program
: must be a parameterless procedure. However, it seems that there's
: nothing to prevent the main program from being a parameterless function!

The LRM _allows_ both functions and procedures as main programs (even
generic instantiations of library units), and also allows parameters to
those subprograms.  It _requires_ that at least a parameterless procedure
main program be supported.  It also requires that the main subprogram
be a library unit.

Your vendor's "Appendix F" documentation may give more information on
capabilities/limitations for subprograms and parameters for main
programs.

	.Bob.

--
Bob Kitzberger	        +1 (916) 274-3075	        rlk@rational.com
Rational Software Corp., 10565 Brunswick Rd. #11, Grass Valley, CA 95945



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

* Re: Main (function) program with exit(status)
  1994-09-16 15:05 Main (function) program with exit(status) John J Cupak Jr CCP
  1994-09-16 21:39 ` David Emery
  1994-09-16 22:31 ` Bob Kitzberger
@ 1994-09-17  3:18 ` Robert Dewar
  1994-09-17 16:31   ` Mats Weber
  2 siblings, 1 reply; 6+ messages in thread
From: Robert Dewar @ 1994-09-17  3:18 UTC (permalink / raw)


"Most coding standards, and even the LRM, state that the main program
must be a parameterless procedure. However, it seems that there's
nothing to prevent the main program from being a parameterless function!"

The LRM says nothing of the kind. It says "A subprogram that is a library
unit can be used as a main program ...".

It then goes on to say that an implementation *may* but certainly not
*must* limit main programs, but must in any case allow parameterless
procedures.

Given this, when writing portable code, stick to parameterless procedures.

But there is nothing to stop an implementor allowing functions to return
a status (or whatever), or even to accept arguments (argc, argv???)

GNAT allows either parameterless procedures, or functions returning any
integer type, and interpretes the integer as a return code, as in this
example.

Still, don't use this in portable code!




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

* Re: Main (function) program with exit(status)
  1994-09-17  3:18 ` Robert Dewar
@ 1994-09-17 16:31   ` Mats Weber
  1994-09-23 14:35     ` Main (function) program with exit(stat Bob Gilbert
  0 siblings, 1 reply; 6+ messages in thread
From: Mats Weber @ 1994-09-17 16:31 UTC (permalink / raw)


Was it ever considered that a task should be the main program instead
of a subprogram ?

I think that this would be more logical and would avoid that hidden
environment task calling the main subprogram.

Of course, this would make it more difficult for compilers to know
whether or not the tasking kernel must be linked in.



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

* Re: Main (function) program with exit(stat
  1994-09-17 16:31   ` Mats Weber
@ 1994-09-23 14:35     ` Bob Gilbert
  0 siblings, 0 replies; 6+ messages in thread
From: Bob Gilbert @ 1994-09-23 14:35 UTC (permalink / raw)


In article mad@info.epfl.ch, weber@lglsun.epfl.ch (Mats Weber) writes:
->Was it ever considered that a task should be the main program instead
->of a subprogram ?
->
->I think that this would be more logical and would avoid that hidden
->environment task calling the main subprogram.
->
->Of course, this would make it more difficult for compilers to know
->whether or not the tasking kernel must be linked in.

I beleive that some compiler's do treat the main program like a task.
I rather like the idea.

-Bob





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

end of thread, other threads:[~1994-09-23 14:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-09-16 15:05 Main (function) program with exit(status) John J Cupak Jr CCP
1994-09-16 21:39 ` David Emery
1994-09-16 22:31 ` Bob Kitzberger
1994-09-17  3:18 ` Robert Dewar
1994-09-17 16:31   ` Mats Weber
1994-09-23 14:35     ` Main (function) program with exit(stat Bob Gilbert

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