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!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wn13feed!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> <1190929570.915553.284000@19g2000hsx.googlegroups.com> X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Fri, 28 Sep 2007 18:07:36 GMT NNTP-Posting-Host: 12.64.18.177 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1191002856 12.64.18.177 (Fri, 28 Sep 2007 18:07:36 GMT) NNTP-Posting-Date: Fri, 28 Sep 2007 18:07:36 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:2194 Date: 2007-09-28T18:07:36+00:00 List-Id: As for the "pragma Ada_05 ( name ) ;" It looks like it will not work for your "Ada_95" user defined package and "Ada_05" Ada defined package. Now for conditional compilation, well I did forget to add the sixth one. Which is the laymans answer and it always works, if you follow the instructions. -- -- Uncomment one and only one of the following lines: -- -- with Package_1 ; use Package_1 ; -- Ada_95 version package -- with Package_2 ; use Package_2 ; -- Ada_2005 version package Now to show one example of the IF-THEN-ELSE-END concept. And it is a lot of work if you have more than a couple of routines to set up. -- -------- -- -- TEST.ADB -- -- -------- -- -- -- There are a number of ways to use the "IF-THEN-ELSE-END" -- structure, this version is one. And it does generate code -- for the "IF-THEN-ELSE-END" statements. -- with Test1 ; procedure test is -- -- True: use Alpha routines aka "user included package" -- -- False: use Beta routine aka "system define package" -- package IO_Package is new Test1 ( False ) ; use IO_Package ; -- Assign default package -- -- Use User created package -- package Package_IO is new Test1 ( True ) ; begin Put_Line.all ( "This is a test" ) ; Package_IO.Put_Line.all ( "Try this One" ) ; end test ; -- --------- -- -- TEST1.ADS -- -- --------- -- -- -- This Generic package defines the program global routines, the -- redefined Ada system routines and the user created routines. -- with Ada.Text_IO ; generic Configure : boolean ; package test1 is type Procedure_String_Type is access procedure ( item : String ) ; ------------------------------- -- Define package procedures -- ------------------------------- Put_Line : Procedure_String_Type ; -- -- define other declared routines/variables needed -- private ------------------------------- -- Emulate system procedures -- ------------------------------- procedure Alpha ( szTemp : string ) ; ----------------------------------------------- -- Redefine/Rename system supplied procedure -- ----------------------------------------------- procedure Beta ( Item : in String ) renames Ada.Text_IO.Put_Line ; end test1 ; -- --------- -- -- TEST1.ADB -- -- --------- -- -- -- This Generic body package defines the user created routines and -- this package does contain a initialize routine that configures -- the package. -- -- -- IF-THEN-ELSE-END -- Yes, the compiler does generate code for -- -- this type of statament. -- -- Also, it is easy to insert a statement in -- -- the wrong place. -- -- This works! Even though there is a person that says this will -- not work. -- If this does not you better find a different language to use. -- Because it means the Ada "IF" statement does not work? -- with Ada.Text_IO ; package body test1 is ------------------------------- -- Emulate system procedures -- ------------------------------- procedure Alpha ( szTemp : string ) is begin Ada.Text_IO.Put_Line ( "Alpha: " & szTemp ) ; end ; ----------------------- -- Initial package -- ----------------------- begin -- test1 -- -- Like I said, this is the old way of doing this by embedding -- the configuration code in the source. But it does work. -- Of course you could use a CASE statement instead, if you need -- more than two options or packages set up. -- if Configure then Put_Line := Alpha'Access ; else Put_Line := Beta'Access ; end if ; end test1 ; In <1190929570.915553.284000@19g2000hsx.googlegroups.com>, Jerry writes: >On Sep 27, 8:26 am, a...@anon.org (anon) wrote: > >Thanks, anon, for the detailed answer. > >> >> 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. > >OK, but my "problem" is in declaring types which I want to be visible >in 95 but not visible in 05, as 05 provides them itself. An "IF-THEN- >ELSE-END" solution would have to be in the executable part of the >program (right?). > > >> 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 ; >> >Same comment as above--how would this work for type declarations? >Could I follow the type declaration with the pragma? Also, I need to >conditionally have a with clause. For example, if using Ada 2005, I >need a line like this: > > with Ada.Numerics.Long_Real_Arrays; > use Ada.Numerics.Long_Real_Arrays; > >(This is where the vector and matrix declarations are.) > >Jerry > >