comp.lang.ada
 help / color / mirror / Atom feed
From: anon@anon.org (anon)
Subject: Re: Pragma for conditional compilation? (Ada 2005 vs. 95)
Date: Thu, 27 Sep 2007 15:26:47 GMT
Date: 2007-09-27T15:26:47+00:00	[thread overview]
Message-ID: <XYPKi.143875$ax1.97469@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: 1190879769.361848.188220@22g2000hsm.googlegroups.com

There is a "NON STANDARD" GNAT pragma. 

"conditional compilation" is undefined in the LRM or in Ada. A simple 
reason is Ada prevents intermix specification or packages by not allowing 
"conditional compilation". 

Note: Java is bad about allowing older specs routines to be compiled and 
used in newer java compiler. It does give an error message but it still 
compiles the code and will run with unpredictablity results.

Now all Ada compiling systems do address the issue of "conditional 
compilation" in there own way. And all accept the makefile type which is 
the best.

Now for Gnat:

First, is the tried and true version of using a OS script file or makefile 
to include the correct separate Ada packages. GNAT uses this in the 
source by having a number of packages that are the same package but 
for different OSs or CPUs. Such as "system-aix.ads", 
"system-freebsd-x86.ads", "system-linux-alpha.ads", 
"system-linux-x86.ads", "system-vms_64.ads" etc. This is the normal 
and best way if you planning to release the source code to the general 
public because you do not want to limit the users from compiling 
your software package. 

The second is to use the GNAT project with separate file structures. 
And in this version the project to chooses the file with a conditional 
switch in the command line.

In both previous design the code is straight foreward and prohibits
inserting and mixing the different specifications which can cause 
unpredictable behavior. In this case it all Ada 95, or all Ada 2005 
specs not both.

The third real old way is to code in the option by a "IF-THEN-ELSE-END" 
statements and use a Global constant variable(s). Its low tech but it 
still works.  GNAT uses this in the compiler. If you check the private 
section in the System package.  Those constants defines the default 
operations of the compiler. And example is the "OpenVMS" variable will 
to False unless it was compiled for OpenVMS. But you need to be careful 
that you call the correct routines. 

The next two ways are GNAT only. Even though other Ada system may 
have a similar ways.

The fourth, is to use "gnat preprocess" or "gnatprep" program. But 
you may have to rewrite the code if you use other Ada system.

The fifth is a "NON STANDARD" way that GNAT introduce with the
pre-release of Ada_2005 which is to use the "pragma Ada_05 ( name ) ;" 

Example:

-- For GNAT you can create a routine that is define and is usable 
-- only in Ada_2005 specs, by using the GNAT pragma Ada_05.
--
-- Gnat uses this concept in the  Ada.Text_IO package. Just 
-- search for "Ada_05" in the file "a-textio.ads". There are 
-- two Get_Line functions. If the system is compiled with 
-- "pragma Ada_83 ;" or "pragma Ada_95" the compile will not 
-- allow a call to these routines. But under Ada_05 the routine is 
-- visible.
--
-- Defined in the specification file.

   procedure Routine ;
   pragma Ada_05 ( Routine ) ;


--
-- Defined in the body file.
--
   procedure Routine is 
     begin -- Routine
        null ;
     end Routine ;



In <1190879769.361848.188220@22g2000hsm.googlegroups.com>,  Jerry <lanceboyle@qwest.net> writes:
>Is there a pragma to designate some lines of Ada for conditional
>compilation depending on if the compiler is Ada 2005 or not?
>
>I have made some bindings that use some of the declarations from Annex
>G.3 which relates to vector-matrix stuff which is new to Ada 2005. If
>the compiler provides those declarations (i.e., is 2005), I want to
>use the compiler's version because I figure that is the cleanest way
>to get things done. If the compiler is Ada 95, I instead want to
>provide the declarations myself.
>
>Currently, I handle this by commenting out the declarations of my own
>if Ada 2005 and uncomment them if Ada 95. (There are a couple of
>"with" and "use" lines that also have to be (un)commented but it is a
>similar situation.)
>
>I'm guessing this is an Ada "no-no" but would be interested to know
>for sure.
>
>Jerry
>




  parent reply	other threads:[~2007-09-27 15:26 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-27  7:56 Pragma for conditional compilation? (Ada 2005 vs. 95) Jerry
2007-09-27  9:31 ` Georg Bauhaus
2007-09-27 16:59   ` Pascal Obry
2007-09-27 21:56     ` Jerry
2007-09-27  9:52 ` Stephen Leake
2007-09-27  9:58 ` Brian Drummond
2007-09-27 15:26 ` anon [this message]
2007-09-27 21:46   ` Jerry
2007-09-28  4:55     ` Jeffrey R. Carter
2007-09-28 12:15       ` Jeffrey Creem
2007-09-28 14:06         ` Jean-Pierre Rosen
2007-09-28 15:24           ` Ludovic Brenta
2007-09-28 16:08             ` Jean-Pierre Rosen
2007-09-28 17:54               ` Georg Bauhaus
2007-09-28 18:19                 ` Pascal Obry
2007-09-28 20:02                   ` Stefan Bellon
2007-09-28 20:14                     ` Pascal Obry
2007-09-28 20:26                       ` Stefan Bellon
2007-09-29 10:24                     ` Stephen Leake
2007-09-28 20:04                   ` Simon Wright
2007-09-28 20:11                     ` Pascal Obry
2007-09-29 10:29                     ` Stephen Leake
2007-09-29 10:18               ` Stephen Leake
2007-09-28 18:07     ` anon
2007-09-29 22:13 ` Jerry
2007-09-30 10:54   ` Stephen Leake
replies disabled

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