From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6426898aedaa5880 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wn14feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Pragma for conditional compilation? (Ada 2005 vs. 95) Reply-To: anon@anon.org (anon) References: <1190879769.361848.188220@22g2000hsm.googlegroups.com> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Thu, 27 Sep 2007 15:26:47 GMT NNTP-Posting-Host: 12.64.198.151 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1190906807 12.64.198.151 (Thu, 27 Sep 2007 15:26:47 GMT) NNTP-Posting-Date: Thu, 27 Sep 2007 15:26:47 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:2162 Date: 2007-09-27T15:26:47+00:00 List-Id: 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 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 >