Main procedure inside a package?



  • 1. No call for Ada (was Announcing new scripting/prototyping language)
    chris wrote: >Assuming it is true that an Ada programmer is 10 times more productive >than a Java programmer, it can only be so assuming *equivalent* tools >are available to do the job at hand and equivalent programming skill (no >point in a comparison otherwise). The tool is the language. Vinzent.
  • 2. Importing some special C functions
    Hello, I'm under windows, and I'm using GNAT 3.15p. I'd like to access serial links, but without using Win32 Bindings. so, I have to import C functions like read, write, open, and select. For most of them, I did not encounter problem. I suppose the linker uses the C functions it has in the gnat C library. But it fails for the select function : the linker can't find it. So, I suppose there is no select function in the C library of Gnat. That's why I'm asking help about how to do that ? I mean, how making Gnat importing C functions ? I've got Cygwin installed, so I guess I could use its C library. But no idea how to do it. If someone could help, it would be great. Thanks in advance, -- Alex
  • 3. Concurrency in Ada in a Linux and Solaris
    Hi, The code bellow compiled and executed in a Linux system [1] doesn't write nothing at output. However, the same code compiled and executed in a Solaris system [2] run right [3]. Any idea? [1] Linux, debian testing, gnat 3.15p-7, gcc 3.3 [2] Solaris 5.7, gnat 3.11, gcc 2.95 [3] ./principal RsiTimer Interrupcion?PetekanInterrupcion?... -- code -- with ada.text_IO; procedure principal is task printer is entry put(s: in string); entry put_line(s: in string); end printer; task body printer is begin loop select accept put(s: in string) do Ada.Text_IO.Put(s); end put; or accept put_line(s: in string) do Ada.Text_IO.Put_Line(s); end put_line; end select; end loop; end printer; task rsi is entry interrupcion; end rsi; task body rsi is begin printer.put("Rsi"); loop select accept interrupcion do printer.Put("Petekan"); end interrupcion; or delay 1.0; printer.Put("FalloRSI"); end select; end loop; end rsi; task timer; task body timer is begin printer.Put_Line("Timer"); loop printer.Put("Interrupcion?"); select rsi.interrupcion; or delay 0.5; printer.Put_Line("Rsi no trata interrupcion"); end select; end loop; end timer; begin Null; end principal;

Main procedure inside a package?

Postby wojtek » Thu, 04 May 2006 21:40:39 GMT


Is it possible for the main procedure to be inside a package? The
compiler is GNAT.

Re: Main procedure inside a package?

Postby Pascal Obry » Thu, 04 May 2006 22:39:16 GMT

 XXXX@XXXXX.COM  a rit :

No, the main procedure must be a library level procedure. I think that
there is another restriction: this procedure should not have parameters
(I have no easy way to check that right now).



--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|               http://www.**--****.com/ 
--| "The best way to travel is by means of imagination"
--| gpg --keyserver --recv-key C1082595

Re: Main procedure inside a package?

Postby Martin Dowie » Fri, 05 May 2006 01:04:46 GMT

That would make your program potentially non-portable. The only form of 
main procedure" that is required to be supported is "However, an 
implementation is required to support all main subprograms that are 
public parameterless library procedures." (RM 10.2.27)
-- Martin

Re: Main procedure inside a package?

Postby Jean-Pierre Rosen » Fri, 05 May 2006 01:12:11 GMT

Pascal Obry a rit :

Anything can be a main subprogram (the restriction was for 83), however 
only parameterless library procedures are guaranteed to be portable:

LRM 10.2(29):
An implementation may restrict the kinds of subprograms it supports as 
main subprograms. However, an implementation is required to support all 
main subprograms that are public parameterless library procedures.

How to define the main subprogram (including the case where it is not a 
library procedure) is implementation defined, i.e. RTFM!
            J-P. Rosen ( XXXX@XXXXX.COM )
Visit Adalog's web site at  http://www.**--****.com/ 

Re: Main procedure inside a package?

Postby Martin Krischik » Fri, 05 May 2006 01:47:32 GMT


The compiler would not know which procedure should be main because the main
procedure can be called anything you like.

However It can be a child procedure to a package. I use this feature quite
often when I have packages just for one program. Works like this:

package My_Package is
end My_Package;

procedure My_Package.My_Main is
end My_Package.My_Main;

mailto:// XXXX@XXXXX.COM 
Ada programming at:  http://www.**--****.com/ 

Re: Main procedure inside a package?

Postby Frank J. Lhota » Fri, 05 May 2006 03:04:12 GMT

Even for Ada 83, a main program was not required to be a parameterless 
library procedure. I recall seeing at least one validated Ada 83 
compiler that also allowed the main program to be a library level 
parameterless function returning an integer. The result of such a 
function sets the return code of the resulting process.

For both Ada 83 and Ada 95, however, the only portable form for a main 
program is a library parameterless library procedure.

Re: Main procedure inside a package?

Postby Rolf » Fri, 05 May 2006 04:41:36 GMT

> Is it possible for the main procedure to be inside a package? The

with My_Package;
procedure Main is begin My_Package.Main; end;

Re: Main procedure inside a package?

Postby Wojtek » Sat, 06 May 2006 05:28:09 GMT

Thank you.

Re: Main procedure inside a package?

Postby Robert A Duff » Wed, 10 May 2006 09:32:15 GMT

Jean-Pierre Rosen < XXXX@XXXXX.COM > writes:

True, but most Ada implementations support only the minimum required,
here -- no main functions, no parameters on main procedures, and no main
procedures nested in packages.

- Bob

Re: Main procedure inside a package?

Postby Sathish Veluswamy » Fri, 12 May 2006 17:34:12 GMT

First u have to know that package cannot be executed directly. more
than that if u create a main procedure inside the package then the
compiler is unable to identify that main procedure and that main
procedure will be treated as a normal procedure inside that particular

Similar Threads:

1.procedure inside package body and modelsim error

2.main() called inside main()


int main(void)
  return 0;

wat does the standard says about the above code snippet?

3.module procedure in main program

The following program is bad f95 because it has a MODULE PROCEDURE 
declaration in a main program instead of in a module, where one is
declaring a generic name for which the specific procedures are 
internal. But did the standard have to disallow that? Some compilers 
allow it,presumably as a language extension, printing 
 complex case sqr((0,2)) = (-4.000000,0.0000000E+00)
 real    case sqr( 2.0)  =   4.000000
as I had expected. 

PROGRAM squaring
PRINT*,'complex case sqr((0,2)) =',sqr((0,2))
PRINT*,'real    case sqr( 2.0)  =',sqr( 2.0 )
    rsqr = x**2
    csqr = z**2
  END FUNCTION     csqr
END PROGRAM squaring

Unless that could cause some ambiguity which I have failed to see,
I suggest that f2008 either allow it, or introduce a new keyword
INTERNAL PROCEDURE that one could use in an interface block in a 
main program or an external subprogram when, as above, the specific 
procedures it refers to are internal. 

The same issue could not arise in an internal subprogram unless f2008 
allows them to contain internal subprograms.

John Harper, School of Mathematics, Statistics and Computer Science, 
Victoria University, PO Box 600, Wellington, New Zealand
e-mail  XXXX@XXXXX.COM  phone (+64)(4)463 5341 fax (+64)(4)463 5045

4.Importing variables from Main Expect Body to Procedures

After much Google searching and wasting time, I am still stuck on a
fairly simple problem.  I have written an expect script in which the
lindex function is used to receive a password from the outside but
then I got fancy and am trying to import it in to a procedure.  The
manual says that all variables are local unless you use the global
designation which I did with no effect at all.  Here is a
stripped-down example of the script.  The complaint from expect -d is
that the variable pw can't be read.

#!/usr/local/bin/expect -f
#Pick up first argument as password.
set pw [lindex $argv 0]
#This has the proper value anywhere in the main body.
#Feed it to proc login.
proc login { } {
send "$pw\r"
expect {
-exact "ord" {
send -- ""
expect -exact "\$"
send -- "exit\r"
expect eof
exit 1
-exact "\$" {

	I did try 

global pw

and occupied a few more bytes of disk space, but nothing seems to
import that variable into proc login.

	The other lines in the script do work if I hard-code the
variable in to the procedure so this little problem is all that
separates me from victory.:-).  Any constructive ideas are much

Martin McCormick WB5AGZ  Stillwater, OK 
Information Technology Division Network Operations Group

5.main or procedure

Hi there,

When I .compile a procedure, it says,
You compiled a main program while inside a procedure. Returning.

And all the information before the compilation was lost.

How to fix it?


6. atv inside procedures

7. Procedures and functions inside xbScript ASP app

8. how to execute inkey() procedure inside get object

Return to ada


Who is online

Users browsing this forum: No registered users and 13 guest