comp.lang.ada
 help / color / mirror / Atom feed
* Conditional compilation in Ada?
@ 2004-11-16 18:30 jtg
  2004-11-16 18:45 ` Marius Amado Alves
                   ` (6 more replies)
  0 siblings, 7 replies; 47+ messages in thread
From: jtg @ 2004-11-16 18:30 UTC (permalink / raw)


I am using Ada for many years now, but recently
I stumbled upon a problem I cannot solve: I need
some kind of conditional preprocessing, which is
commonly used in C programs:

#ifdef CONDITION
  (some source code)
#else
  (other source code)
#endif

How to achieve it with Ada?
I am developing two applications which are very similar
and share the same source code. The only difference is
a small change in a fundamental data structure. Both versions of the
data structure are mostly handled the same way (within thousands of
lines of source code), but there are some 10 or 20 (number still
growing) places where minor changes are necessary. What is worse,
during the development every several hours I have to prepare
and run both the applications. To do this, I have to perform
"human preprocessing": find those places, comment lines
for app1, and uncomment lines for app2. This is very error prone and
I have already made a mistake.

Any hints?



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

* Re: Conditional compilation in Ada?
  2004-11-16 18:30 Conditional compilation in Ada? jtg
@ 2004-11-16 18:45 ` Marius Amado Alves
  2004-11-16 20:41   ` Nick Roberts
  2004-11-16 19:03 ` Jeffrey Carter
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 47+ messages in thread
From: Marius Amado Alves @ 2004-11-16 18:45 UTC (permalink / raw)
  To: comp.lang.ada

> Any hints?

Gnatprep.




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

* Re: Conditional compilation in Ada?
  2004-11-16 18:30 Conditional compilation in Ada? jtg
  2004-11-16 18:45 ` Marius Amado Alves
@ 2004-11-16 19:03 ` Jeffrey Carter
  2004-11-16 19:13   ` Hyman Rosen
  2004-11-16 19:06 ` tmoran
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 47+ messages in thread
From: Jeffrey Carter @ 2004-11-16 19:03 UTC (permalink / raw)


jtg wrote:

> I am developing two applications which are very similar
> and share the same source code. The only difference is
> a small change in a fundamental data structure. Both versions of the
> data structure are mostly handled the same way (within thousands of
> lines of source code), but there are some 10 or 20 (number still
> growing) places where minor changes are necessary. What is worse,
> during the development every several hours I have to prepare
> and run both the applications. To do this, I have to perform
> "human preprocessing": find those places, comment lines
> for app1, and uncomment lines for app2. This is very error prone and
> I have already made a mistake.
> 
> Any hints?

Yes. Don't use preprocessing.

It sounds as if you have a good use for a variant record:

type Common_Stuff is record
    ...
end record;

type Variant_1_Stuff is record
    ...
end record;

type Variant_2_Stuff is record
    ...
end record;

type Data_Structure (Variant_1 : Boolean) is record
    Common : Common_Stuff;

    case Variant_1 is
    when True =>
       Var_1 : Variant_1_Stuff;
    when False =>
       Var_2 : Variant_2_Stuff;
    end case;
end record;

Then you can write

Variant_1 : constant Boolean := ...;

X : Data_Structure (Variant_1 => Variant_1);

...
Common_Processing (Common => X.Common);

if X.Variant_1 then
    Variant_1_Processing (Var_1 => X.Var_1);
else
    Variant_2_Processing (Var_2 => X.Var_2);
end if;

If you anticipate additional variants, it's probably better to use an 
enumeration type for the discriminant:

type Variant_ID is (Variant_1, Variant_2);

type Data_Structure (Variant : Variant_ID) ...

case X.Variant is
when Variant_1 =>
    Variant_1_Processing ...

This is easily expanded by adding additional variants, and the compiler 
will tell you if you've missed anything.

-- 
Jeff Carter
"I've got to stay here, but there's no reason
why you folks shouldn't go out into the lobby
until this thing blows over."
Horse Feathers
50




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

* Re: Conditional compilation in Ada?
  2004-11-16 18:30 Conditional compilation in Ada? jtg
  2004-11-16 18:45 ` Marius Amado Alves
  2004-11-16 19:03 ` Jeffrey Carter
@ 2004-11-16 19:06 ` tmoran
  2004-11-17  9:39   ` Adrien Plisson
  2004-11-17  2:44 ` Steve
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 47+ messages in thread
From: tmoran @ 2004-11-16 19:06 UTC (permalink / raw)


>a small change in a fundamental data structure. Both versions of the
>data structure are mostly handled the same way (within thousands of
>lines of source code), but there are some 10 or 20 (number still
>growing) places where minor changes are necessary. What is worse,
  You can use an "if" statement.
if Is_Version1 then ...
else ...
  If you define Is_Version1 at the top, or in another small package, as
  Is_Version1 : constant Boolean := True;
then an intelligent compiler will not generate any code for the impossible
Is_Version1 = False condition or the if-test itself.  That is, it will be
identical in effect to C conditional compilation.
  If the "minor changes" are similar, you could change the processing in
the many places in the huge module to instead call a subroutine and then
only make changes/ifs in the body of that subroutine (or subroutines).



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

* Re: Conditional compilation in Ada?
  2004-11-16 19:03 ` Jeffrey Carter
@ 2004-11-16 19:13   ` Hyman Rosen
  2004-11-16 19:41     ` Björn Lundin
                       ` (2 more replies)
  0 siblings, 3 replies; 47+ messages in thread
From: Hyman Rosen @ 2004-11-16 19:13 UTC (permalink / raw)


Jeffrey Carter wrote:
> Yes. Don't use preprocessing.

Yes, especially in the way he's proposing.
Leaving little #ifdefs everywhere is bad practice even
in languages which allow it.

> It sounds as if you have a good use for a variant record:

The OP is running two separate programs. There should be a
better solution than forcing him to make runtime tests for
something which is static.

A description of the data structure and its varieties is
needed before we can offer really sage advice.



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

* Re: Conditional compilation in Ada?
  2004-11-16 19:13   ` Hyman Rosen
@ 2004-11-16 19:41     ` Björn Lundin
  2004-11-16 20:08     ` tmoran
  2004-11-16 20:43     ` Martin Dowie
  2 siblings, 0 replies; 47+ messages in thread
From: Björn Lundin @ 2004-11-16 19:41 UTC (permalink / raw)
  To: comp.lang.ada

tisdag 16 november 2004 20:13 skrev Hyman Rosen:
> The OP is running two separate programs. There should be a
> better solution than forcing him to make runtime tests for
> something which is static.
>
> A description of the data structure and its varieties is
> needed before we can offer really sage advice.

It all depends on _what_ differs. I work with a system running on Aix and 
Windows. We have internal process communication, which is done with shared 
memory + semphores on Aix and with memory mapped files on windows.
Doesn't help with smart data structrues when you do a pragma Import.

What we usually do when we can't solve the platform differences, is to write 
that in (yack) C, and export the same function names and arguments, and have
one c-file per platform. This could be solved in one file with #ifdefs but
we prefer a c-file or more _per_ platform

We then have the same Ada files, which imports the functions from respective 
platform's c-file
/Björn




> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada



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

* Re: Conditional compilation in Ada?
  2004-11-16 19:13   ` Hyman Rosen
  2004-11-16 19:41     ` Björn Lundin
@ 2004-11-16 20:08     ` tmoran
  2004-11-16 20:27       ` Hyman Rosen
  2004-11-16 20:43     ` Martin Dowie
  2 siblings, 1 reply; 47+ messages in thread
From: tmoran @ 2004-11-16 20:08 UTC (permalink / raw)


> The OP is running two separate programs.
I beg to quibble.  If a program acts differently depending on a command
line parameter, is it two different programs?  The parameter is certainly
static during any one run.  If a program (an OS, say) examines its
hardware environment and then uses/ignores certain code depending on
what's there, is it one program or many?  If a program has a Windows
version and a Linux version, is it two different programs?  The
concept of "a single program" is ill-defined.

> There should be a better solution than forcing him to make runtime tests
> for something which is static.
  With a compiler that does dead code elimination there will be no runtime
test if he uses a "constant Boolean := ".



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

* Re: Conditional compilation in Ada?
  2004-11-16 20:08     ` tmoran
@ 2004-11-16 20:27       ` Hyman Rosen
  2004-11-16 23:49         ` Jim Rogers
  0 siblings, 1 reply; 47+ messages in thread
From: Hyman Rosen @ 2004-11-16 20:27 UTC (permalink / raw)


tmoran@acm.org wrote:
>>The OP is running two separate programs.
> 
> I beg to quibble.

Well, here's what he said:
    "I am developing two applications which are very similar
     and share the same source code. The only difference is
     a small change in a fundamental data structure."

> With a compiler that does dead code elimination there will
 > be no runtime test if he uses a "constant Boolean := ".

In any case, prudence dictates that the differences should be
put in one place, not scattered all over. But without a look
at the OP's code, it's hard to make suggestions.



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

* Re: Conditional compilation in Ada?
  2004-11-16 18:45 ` Marius Amado Alves
@ 2004-11-16 20:41   ` Nick Roberts
  2004-11-17  8:36     ` Alex R. Mosteo
  0 siblings, 1 reply; 47+ messages in thread
From: Nick Roberts @ 2004-11-16 20:41 UTC (permalink / raw)


"Marius Amado Alves" <amado.alves@netcabo.pt> wrote in message 
news:mailman.103.1100630792.10401.comp.lang.ada@ada-france.org...
>> Any hints?
>
> Gnatprep.

In a little more detail, declare the things that differ (types, associated 
operations) in two separate packages, say Stuff_For_Playstation and 
Stuff_For_XBox, then put something like this:

Compile_Target := XBox

into a text file called "targspec.txt" (say), and then something like this 
in the appropriate places in your source files:

   with Stuff_For_$Compile_Target;
   ...
   package Target_Specific renames Stuff_For_$Compile_Target;
   ...
      Target_Specific.Reset_Joystick; -- or whatever

and rename every so doctored source file myfile.ads to myfile.adsp (and 
myfile.adb to myfile.adbp) and then run:

   gnatprep myfile.adsp myfile.ads targspec.txt -c -r

for each such source file, and then compile as normal. Documentation for 
gnatprep is in the GNAT User's Guide.

Obviously, you change "Compile_Target := XBox" to "Compile_Target := 
Playstation" to recompile for a different target.

The idea is to minimise the number of times you use a $ macro or #if in your 
source files, within reason, and put as much as possible into the different 
specific packages. Things tend to be easier to debug this way. You may find 
that you do not have to use gnatprep at all, but instead you could just have 
a separate file "target_specific.ads" which contains the two lines:

   with Stuff_For_XBox;
   package Target_Specific renames Stuff_For_XBox;

which you simply change to:


   with Stuff_For_Playstation;
   package Target_Specific renames Stuff_For_Playstation;

in order to recompile for a different target.

-- 
HTH
Nick Roberts





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

* Re: Conditional compilation in Ada?
  2004-11-16 19:13   ` Hyman Rosen
  2004-11-16 19:41     ` Björn Lundin
  2004-11-16 20:08     ` tmoran
@ 2004-11-16 20:43     ` Martin Dowie
  2 siblings, 0 replies; 47+ messages in thread
From: Martin Dowie @ 2004-11-16 20:43 UTC (permalink / raw)


Hyman Rosen wrote:
> Jeffrey Carter wrote:
>> Yes. Don't use preprocessing.
>
> Yes, especially in the way he's proposing.
> Leaving little #ifdefs everywhere is bad practice even
> in languages which allow it.
>
>> It sounds as if you have a good use for a variant record:
>
> The OP is running two separate programs. There should be a
> better solution than forcing him to make runtime tests for
> something which is static.

Why would this require a run-time check? The actual variant is known at 
compile time and stored as a constant (in the example). 





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

* Re: Conditional compilation in Ada?
  2004-11-16 20:27       ` Hyman Rosen
@ 2004-11-16 23:49         ` Jim Rogers
  0 siblings, 0 replies; 47+ messages in thread
From: Jim Rogers @ 2004-11-16 23:49 UTC (permalink / raw)


Hyman Rosen <hyrosen@mail.com> wrote in news:1100636869.12000
@master.nyc.kbcfp.com:

> tmoran@acm.org wrote:
>>>The OP is running two separate programs.
>> 
>> I beg to quibble.
> 
> Well, here's what he said:
>     "I am developing two applications which are very similar
>      and share the same source code. The only difference is
>      a small change in a fundamental data structure."
> 

If these are indeed two different applications demonstrating
significant code reuse, then the proper answer is found in
a configuration-managed build system rather than in 
conditional compilation.

Jim Rogers




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

* Re: Conditional compilation in Ada?
  2004-11-16 18:30 Conditional compilation in Ada? jtg
                   ` (2 preceding siblings ...)
  2004-11-16 19:06 ` tmoran
@ 2004-11-17  2:44 ` Steve
  2004-11-17 20:30   ` Jeffrey Carter
  2004-11-17  9:28 ` Martin Krischik
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 47+ messages in thread
From: Steve @ 2004-11-17  2:44 UTC (permalink / raw)


In general, the most effective way to make it easy to share code is to
isolate the parts that are likely to change between uses, and provide
different implementations for their uses.

Without knowing more details, this sounds like a good place to use OOP.

Instead of directly manipulating the data structure, use procedures to
manipulate the data structure, and dispatch to the appropriate instance type
for your target.

IMHO conditional compilation is a bad thing.  Especially if its use is not
restricted.

Steve
(The Duck)


"jtg" <jtg77@poczta.onet.pl> wrote in message
news:cndgus$9g6$1@korweta.task.gda.pl...
> I am using Ada for many years now, but recently
> I stumbled upon a problem I cannot solve: I need
> some kind of conditional preprocessing, which is
> commonly used in C programs:
>
> #ifdef CONDITION
>   (some source code)
> #else
>   (other source code)
> #endif
>
> How to achieve it with Ada?
> I am developing two applications which are very similar
> and share the same source code. The only difference is
> a small change in a fundamental data structure. Both versions of the
> data structure are mostly handled the same way (within thousands of
> lines of source code), but there are some 10 or 20 (number still
> growing) places where minor changes are necessary. What is worse,
> during the development every several hours I have to prepare
> and run both the applications. To do this, I have to perform
> "human preprocessing": find those places, comment lines
> for app1, and uncomment lines for app2. This is very error prone and
> I have already made a mistake.
>
> Any hints?





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

* Re: Conditional compilation in Ada?
  2004-11-16 20:41   ` Nick Roberts
@ 2004-11-17  8:36     ` Alex R. Mosteo
  0 siblings, 0 replies; 47+ messages in thread
From: Alex R. Mosteo @ 2004-11-17  8:36 UTC (permalink / raw)


Nick Roberts wrote:
> "Marius Amado Alves" <amado.alves@netcabo.pt> wrote in message 
> news:mailman.103.1100630792.10401.comp.lang.ada@ada-france.org...
> 
>>>Any hints?
>>
>>Gnatprep.
> 
> 
> In a little more detail, declare the things that differ (types, associated 
> operations) in two separate packages, say Stuff_For_Playstation and 
> Stuff_For_XBox, then put something like this:
> 
> Compile_Target := XBox
> 
> into a text file called "targspec.txt" (say), and then something like this 
> in the appropriate places in your source files:
> 
>    with Stuff_For_$Compile_Target;
>    ...
>    package Target_Specific renames Stuff_For_$Compile_Target;
>    ...
>       Target_Specific.Reset_Joystick; -- or whatever
> 
> and rename every so doctored source file myfile.ads to myfile.adsp (and 
> myfile.adb to myfile.adbp) and then run:
> 
>    gnatprep myfile.adsp myfile.ads targspec.txt -c -r
> 
> for each such source file, and then compile as normal. Documentation for 
> gnatprep is in the GNAT User's Guide.
> 
> Obviously, you change "Compile_Target := XBox" to "Compile_Target := 
> Playstation" to recompile for a different target.
> 
> The idea is to minimise the number of times you use a $ macro or #if in your 
> source files, within reason, and put as much as possible into the different 
> specific packages. Things tend to be easier to debug this way. You may find 
> that you do not have to use gnatprep at all, but instead you could just have 
> a separate file "target_specific.ads" which contains the two lines:
> 
>    with Stuff_For_XBox;
>    package Target_Specific renames Stuff_For_XBox;
> 
> which you simply change to:
> 
> 
>    with Stuff_For_Playstation;
>    package Target_Specific renames Stuff_For_Playstation;
> 
> in order to recompile for a different target.

What I do is to have a folder for every platform-specific code. It must 
conform to a predefined spec, as suggested. Then I have two rules in a 
Makefile. One issues the gnatmake -Iplatform1 and the other -Iplatform2.



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

* Re: Conditional compilation in Ada?
  2004-11-16 18:30 Conditional compilation in Ada? jtg
                   ` (3 preceding siblings ...)
  2004-11-17  2:44 ` Steve
@ 2004-11-17  9:28 ` Martin Krischik
  2004-11-17 13:39   ` Stephen Leake
  2004-11-17 10:02 ` Frank Piron
  2004-11-17 12:27 ` Marin David Condic
  6 siblings, 1 reply; 47+ messages in thread
From: Martin Krischik @ 2004-11-17  9:28 UTC (permalink / raw)


jtg wrote:

> I am using Ada for many years now, but recently
> I stumbled upon a problem I cannot solve: I need
> some kind of conditional preprocessing, which is
> commonly used in C programs:
> 
> #ifdef CONDITION
>   (some source code)
> #else
>   (other source code)
> #endif
> 
> How to achieve it with Ada?

Depends on the Ada compiler you use. GNAT has "GNAT PREPROCESS" or
"gnatprep" for short. You need to RTFM ;-) on how to use "GNAT PREPROCESS".

> I am developing two applications which are very similar
> and share the same source code. The only difference is
> a small change in a fundamental data structure. Both versions of the
> data structure are mostly handled the same way (within thousands of
> lines of source code), but there are some 10 or 20 (number still
> growing) places where minor changes are necessary. What is worse,
> during the development every several hours I have to prepare
> and run both the applications. To do this, I have to perform
> "human preprocessing": find those places, comment lines
> for app1, and uncomment lines for app2. This is very error prone and
> I have already made a mistake.
> 
> Any hints?

Well in AdaCL long ago I used "GNAT PREPROCESS" - however once I learned the
Ada way more closely I removed all use "GNAT PREPROCESS" and used the build
management instead:

All differences where encapsulated in private "XXX.Low_Level" packages. When
suitalble "pagama Inline" was uesd. Those packages where moved ito "NT",
"Linux" and "OS2" directories. The build mamagement picks up the version
needed.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



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

* Re: Conditional compilation in Ada?
  2004-11-16 19:06 ` tmoran
@ 2004-11-17  9:39   ` Adrien Plisson
  2004-11-17 16:39     ` Jacob Sparre Andersen
  0 siblings, 1 reply; 47+ messages in thread
From: Adrien Plisson @ 2004-11-17  9:39 UTC (permalink / raw)


tmoran@acm.org wrote:

>   You can use an "if" statement.
> if Is_Version1 then ...
> else ...
>   If you define Is_Version1 at the top, or in another small package, as
>   Is_Version1 : constant Boolean := True;
> then an intelligent compiler will not generate any code for the impossible
> Is_Version1 = False condition or the if-test itself.  That is, it will be
> identical in effect to C conditional compilation.

will really the compiler not COMPILE the code impossible to reach ? i'm not 
that sure... it will generate no code, and maybe even no check at the entrance, 
but the code is still compiled and checked by the compiler for syntax errors, 
semantic errors and so on.

so, if he has a record:
type Version_1 is record
     Value_Version_1 : Any_Type;
end record

and another version:
type Version_2 is record
     Value_Version_2 : Any_Other_Type;
end record;

then code accessing the Version_1 record will not compile for Version_2, and 
vice versa. the "if" statement is then not an option, and is definitely not 
identical to the C conditional compilation. remember that the C preprocessor 
allows to do conditional COMPILATION, not conditional RUNTIME.

well, before everybody yell, i'm totally aware that this case is typically a 
bad design and should be rewritten using discriminated record. (but some people 
don't quite get it and still write this kind of code, especially in C with #if).

-- 
rien



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

* Re: Conditional compilation in Ada?
  2004-11-16 18:30 Conditional compilation in Ada? jtg
                   ` (4 preceding siblings ...)
  2004-11-17  9:28 ` Martin Krischik
@ 2004-11-17 10:02 ` Frank Piron
  2004-11-17 12:32   ` Georg Bauhaus
  2004-11-17 12:27 ` Marin David Condic
  6 siblings, 1 reply; 47+ messages in thread
From: Frank Piron @ 2004-11-17 10:02 UTC (permalink / raw)


Am Tue, 16 Nov 2004 19:30:39 +0100 schrieb jtg <jtg77@poczta.onet.pl>:

> I am using Ada for many years now, but recently
> I stumbled upon a problem I cannot solve: I need
> some kind of conditional preprocessing, which is
> commonly used in C programs:
>
> #ifdef CONDITION
>   (some source code)
> #else
>   (other source code)
> #endif
>
> How to achieve it with Ada?

We had another problem concerning conditional compilation:
In a project containing roundabout 30 packages, we wanted
to switch on and off debugging messages for each package
individually and for certain levels (application defined
messages, exceptions, include callback procedures from the
GUI part, ...).
We tried with gnatprep but found it not suitable for this
task.
Finally we defined a certain "comment syntax" for the
messages and a debug.conf file format. Then we wrote
an "adaprep" for our purposes which read the debug.conf
- where you can switch on and off debugging for each
package (procedure/function) and set a level - and then
modifies the sources. The resulting sources with debugging
messages are copied to a separate code tree and built.
Sounds complicated but is done now with few commands.
The whole thing works fine for us, but compiling a new
"debug version" may take some time ...

Frank Piron



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

* Re: Conditional compilation in Ada?
  2004-11-16 18:30 Conditional compilation in Ada? jtg
                   ` (5 preceding siblings ...)
  2004-11-17 10:02 ` Frank Piron
@ 2004-11-17 12:27 ` Marin David Condic
  6 siblings, 0 replies; 47+ messages in thread
From: Marin David Condic @ 2004-11-17 12:27 UTC (permalink / raw)


Unfortunately, there isn't any standard Ada way of dealing with 
conditional compilation and not a whole lot of sympathy for it with most 
people in the Ada crowd. (Probably because they've seen it abused so 
much in C programs that they'd rather not allow it into the language 
lest it cause Ada programs to turn into the sort of unholy mess many C 
programs have become.)

People have mentioned gnatprep as a possible answer - which is fine so 
long as all you ever want to use is gnat. If you were dealing with code 
that needed to be made portable across two or more Ada compilers, you'd 
have a problem because gnatprep isn't standard across all compilers. 
(You could probably cobble something together though since it is open 
source.) You can also try pulling some information-hiding tricks and 
isolation of stuff down to package bodies & utilize some form of 
configuration management outside the bounds of Ada to get the desired 
effect. However that often seems to me to be a) overly complicated for 
occasional small problems and b) another non-standard way of dealing 
with the problem.

If you really have large platform/compiler dependent issues, you're 
probably better off biting the bullet and using some kind of 
configuration management tools with isolation of whatever is dependent 
within package bodies. For the smaller-scale problems, you're stuck with 
  only sub-optimal answers.

MDC

jtg wrote:
> I am using Ada for many years now, but recently
> I stumbled upon a problem I cannot solve: I need
> some kind of conditional preprocessing, which is
> commonly used in C programs:

-- 
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jsf.mil/NSFrames.htm

Send Replies To: m   o   d   c @ a   m   o   g
                    c   n   i       c   .   r

     "Power corrupts.  Absolute power is kind of neat"
         -- John Lehman, Secretary of the Navy 1981-1987
======================================================================



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

* Re: Conditional compilation in Ada?
  2004-11-17 10:02 ` Frank Piron
@ 2004-11-17 12:32   ` Georg Bauhaus
  2004-11-17 14:44     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 47+ messages in thread
From: Georg Bauhaus @ 2004-11-17 12:32 UTC (permalink / raw)


Frank Piron wrote:
> we wanted
> to switch on and off debugging messages for each package
> individually and for certain levels 
> We tried with gnatprep but found it not suitable for this
> task.

Perhaps another option is to have

package DEBUG renames Silent_Debugging_Procedures;

or

package DEBUG renames Debugging_Procedures;

inside package bodies? Then statements like

   DEBUG.put_line(...);

might or might not print something.

Is pragma Debug available?


-- Georg Bauhaus



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

* Re: Conditional compilation in Ada?
  2004-11-17  9:28 ` Martin Krischik
@ 2004-11-17 13:39   ` Stephen Leake
  0 siblings, 0 replies; 47+ messages in thread
From: Stephen Leake @ 2004-11-17 13:39 UTC (permalink / raw)
  To: comp.lang.ada

Martin Krischik <martin@krischik.com> writes:

> jtg wrote:
> 
> > I am using Ada for many years now, but recently
> > I stumbled upon a problem I cannot solve: I need
> > some kind of conditional preprocessing, which is
> > commonly used in C programs:
> > 
> > #ifdef CONDITION
> >   (some source code)
> > #else
> >   (other source code)
> > #endif
> > 
> > How to achieve it with Ada?
> 
> Depends on the Ada compiler you use. GNAT has "GNAT PREPROCESS" or
> "gnatprep" for short. You need to RTFM ;-) on how to use "GNAT PREPROCESS".

Actually, you can use gnatprep as a preprocessor for any Ada compiler.

-- 
-- Stephe




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

* Re: Conditional compilation in Ada?
  2004-11-17 12:32   ` Georg Bauhaus
@ 2004-11-17 14:44     ` Dmitry A. Kazakov
  2004-11-18 15:23       ` Georg Bauhaus
  0 siblings, 1 reply; 47+ messages in thread
From: Dmitry A. Kazakov @ 2004-11-17 14:44 UTC (permalink / raw)


On Wed, 17 Nov 2004 13:32:06 +0100, Georg Bauhaus wrote:

> Frank Piron wrote:
>> we wanted
>> to switch on and off debugging messages for each package
>> individually and for certain levels 
>> We tried with gnatprep but found it not suitable for this
>> task.
> 
> Perhaps another option is to have
> 
> package DEBUG renames Silent_Debugging_Procedures;
> 
> or
> 
> package DEBUG renames Debugging_Procedures;
> 
> inside package bodies? Then statements like
> 
>    DEBUG.put_line(...);
>
> might or might not print something.

Put_Line (File, ...); -- File is opened on /dev/null or not (:-))

Seriously, the actual problem with that is:

DEBUG.put_line
(  "Here " & Is.Something ("reasonable complex to evaluate")
);

Arguments of put_line will be always evaluated before being thrown away.
Alas, Ada does not have lazy formal parameters...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Conditional compilation in Ada?
  2004-11-17  9:39   ` Adrien Plisson
@ 2004-11-17 16:39     ` Jacob Sparre Andersen
  0 siblings, 0 replies; 47+ messages in thread
From: Jacob Sparre Andersen @ 2004-11-17 16:39 UTC (permalink / raw)


Adrien Plisson wrote:

> will really the compiler not COMPILE the code impossible to reach ?

No.  It will also compile the unreachable code.  And that is good.
You should never write code that doesn't compile.  One of the big
problems with the C preprocessor is that it prevents the compiler from
checking the deactivated parts for syntax errors.

Anyway: Put the system-specific code in one (or more) separate
packages with a common specification and all the system-variations
hidden in the bodies.

Jacob
-- 
�By becoming continuous, war has fundamentally changed its character.
 In past ages, a war, almost by definition, was something that sooner
 or later came to an end, usually in unmistakable victory or defeat.�
                               -- Nineteen Eighty-Four, George Orwell
�I don't think you can win [the war on terror].�    -- George W. Bush



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

* Re: Conditional compilation in Ada?
  2004-11-17  2:44 ` Steve
@ 2004-11-17 20:30   ` Jeffrey Carter
  2004-11-18  4:09     ` Steve
  0 siblings, 1 reply; 47+ messages in thread
From: Jeffrey Carter @ 2004-11-17 20:30 UTC (permalink / raw)


Steve wrote:

> Without knowing more details, this sounds like a good place to use
> OOP.
> 
> Instead of directly manipulating the data structure, use procedures
> to manipulate the data structure, and dispatch to the appropriate
> instance type for your target.

I would disagree. Using OOP and dispatching means that the decision 
making is dynamic and occurs at run time. Using variant records and case 
statements allows everything to be static and determined at compile time.

-- 
Jeff Carter
"I'm a kike, a yid, a heebie, a hook nose! I'm Kosher,
Mum! I'm a Red Sea pedestrian, and proud of it!"
Monty Python's Life of Brian
77




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

* Re: Conditional compilation in Ada?
  2004-11-17 20:30   ` Jeffrey Carter
@ 2004-11-18  4:09     ` Steve
  2004-11-18  6:49       ` Martin Dowie
  2004-11-18 17:44       ` Jeffrey Carter
  0 siblings, 2 replies; 47+ messages in thread
From: Steve @ 2004-11-18  4:09 UTC (permalink / raw)


I disagree with your argument.

Dynamic dispatching is fairly efficient, and may simplify coding.
Dispatching generally means getting the address of a function from a vtab
rather than calling the function directly.

Using variant records means explicitly checking for the variant type and
taking different action based on the variant.  Creating a new variation of
the record means modifying the original record (modifying proven code is
never a good thing when it is easily avoided) and chasing each part of the
code that takes different action based on the variants.

Using objects means deriving a new object and overloading specific
operations for that object.  The base object isn't touched.

Also: If the object is declared statically, the dispatching may happen
statically.

Steve
(The Duck)


"Jeffrey Carter" <spam@spam.com> wrote in message
news:xxOmd.1541$Tq6.592@newsread3.news.pas.earthlink.net...
> Steve wrote:
>
> > Without knowing more details, this sounds like a good place to use
> > OOP.
> >
> > Instead of directly manipulating the data structure, use procedures
> > to manipulate the data structure, and dispatch to the appropriate
> > instance type for your target.
>
> I would disagree. Using OOP and dispatching means that the decision
> making is dynamic and occurs at run time. Using variant records and case
> statements allows everything to be static and determined at compile time.
>
> -- 
> Jeff Carter
> "I'm a kike, a yid, a heebie, a hook nose! I'm Kosher,
> Mum! I'm a Red Sea pedestrian, and proud of it!"
> Monty Python's Life of Brian
> 77
>





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

* Re: Conditional compilation in Ada?
  2004-11-18  4:09     ` Steve
@ 2004-11-18  6:49       ` Martin Dowie
  2004-11-18 15:17         ` Georg Bauhaus
  2004-11-18 17:34         ` Jeffrey Carter
  2004-11-18 17:44       ` Jeffrey Carter
  1 sibling, 2 replies; 47+ messages in thread
From: Martin Dowie @ 2004-11-18  6:49 UTC (permalink / raw)


"Steve" <nospam_steved94@comcast.net> wrote in message 
news:CfVmd.110500$R05.57670@attbi_s53...
> Using variant records means explicitly checking for the variant type and
> taking different action based on the variant.  Creating a new variation of
> the record means modifying the original record (modifying proven code is
> never a good thing when it is easily avoided) and chasing each part of the
> code that takes different action based on the variants.

But the compiler will help you, so long as you use a 'case' with no 'others' 
branch. And the check on the variant can be done at compile time not 
run-time if it is known and assigned to a constant.

> Using objects means deriving a new object and overloading specific
> operations for that object.  The base object isn't touched.
>
> Also: If the object is declared statically, the dispatching may happen
> statically.

I've seen compilers that do this for the variant record method (most seem to 
in my experience) - is this true for the OO method?

Cheers

-- Martin





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

* Re: Conditional compilation in Ada?
  2004-11-18  6:49       ` Martin Dowie
@ 2004-11-18 15:17         ` Georg Bauhaus
  2004-11-18 19:12           ` Martin Dowie
  2004-11-18 17:34         ` Jeffrey Carter
  1 sibling, 1 reply; 47+ messages in thread
From: Georg Bauhaus @ 2004-11-18 15:17 UTC (permalink / raw)


Martin Dowie <martin.dowie@btopenworld.com> wrote:
 
: I've seen compilers that do this for the variant record method (most seem to 
: in my experience) - is this true for the OO method?

Do you mean, the OO method with dispatching calls?


-- Georg



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

* Re: Conditional compilation in Ada?
  2004-11-17 14:44     ` Dmitry A. Kazakov
@ 2004-11-18 15:23       ` Georg Bauhaus
  2004-11-18 22:10         ` Brian May
  2004-11-20  1:05         ` Conditional compilation in Ada? Dr. Adrian Wrigley
  0 siblings, 2 replies; 47+ messages in thread
From: Georg Bauhaus @ 2004-11-18 15:23 UTC (permalink / raw)


Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:

pragma Ignore ( -- compiler warning 
 DEBUG.put_line
 (  "Here " & Is.Something ("reasonable complex to evaluate")
 )
);

Lazy enough? ;-)

-- Georg Bauhaus



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

* Re: Conditional compilation in Ada?
  2004-11-18  6:49       ` Martin Dowie
  2004-11-18 15:17         ` Georg Bauhaus
@ 2004-11-18 17:34         ` Jeffrey Carter
  1 sibling, 0 replies; 47+ messages in thread
From: Jeffrey Carter @ 2004-11-18 17:34 UTC (permalink / raw)


Martin Dowie wrote:

>>Also: If the object is declared statically, the dispatching may happen
>>statically.
> 
> I've seen compilers that do this for the variant record method (most seem to 
> in my experience) - is this true for the OO method?

Yes. If the compiler can determine the type of the parameter(s), the 
call is compiled statically.

-- 
Jeff Carter
"I fart in your general direction."
Monty Python & the Holy Grail
05




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

* Re: Conditional compilation in Ada?
  2004-11-18  4:09     ` Steve
  2004-11-18  6:49       ` Martin Dowie
@ 2004-11-18 17:44       ` Jeffrey Carter
  2004-11-18 18:03         ` Alex R. Mosteo
  1 sibling, 1 reply; 47+ messages in thread
From: Jeffrey Carter @ 2004-11-18 17:44 UTC (permalink / raw)


Steve wrote:

> Using variant records means explicitly checking for the variant type and
> taking different action based on the variant.  Creating a new variation of
> the record means modifying the original record (modifying proven code is
> never a good thing when it is easily avoided) and chasing each part of the
> code that takes different action based on the variants.

Since the compiler points out any place where you've forgotten, this is 
hardly a problem; indeed, I would claim that it's an advantage over OOP, 
where forgetting to redefine an operation is ignored by the compiler, 
and you get the wrong action instead.

In a well designed system, all the code dealing with the variant record 
and its variants will be together, so there's no "chasing each part of 
the code".

Another advantage of using a variant record is that what happens is 
explicit in the code, not hidden is some package that is not mentioned 
in a context clause.

> Using objects means deriving a new object and overloading specific
> operations for that object.  The base object isn't touched.

And operations that are mistakenly not overridden become run-time errors.

> Also: If the object is declared statically, the dispatching may happen
> statically.

This is true, but it seems that the nature of OP's problem would prevent 
this.

-- 
Jeff Carter
"I fart in your general direction."
Monty Python & the Holy Grail
05




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

* Re: Conditional compilation in Ada?
  2004-11-18 17:44       ` Jeffrey Carter
@ 2004-11-18 18:03         ` Alex R. Mosteo
  2004-11-19  3:00           ` Steve
  0 siblings, 1 reply; 47+ messages in thread
From: Alex R. Mosteo @ 2004-11-18 18:03 UTC (permalink / raw)


Jeffrey Carter wrote:
> Steve wrote:
> 
>> Using variant records means explicitly checking for the variant type and
>> taking different action based on the variant.  Creating a new 
>> variation of
>> the record means modifying the original record (modifying proven code is
>> never a good thing when it is easily avoided) and chasing each part of 
>> the
>> code that takes different action based on the variants.
> 
> 
> Since the compiler points out any place where you've forgotten, this is 
> hardly a problem; indeed, I would claim that it's an advantage over OOP, 
> where forgetting to redefine an operation is ignored by the compiler, 
> and you get the wrong action instead.
> 
> In a well designed system, all the code dealing with the variant record 
> and its variants will be together, so there's no "chasing each part of 
> the code".
> 
> Another advantage of using a variant record is that what happens is 
> explicit in the code, not hidden is some package that is not mentioned 
> in a context clause.
> 
>> Using objects means deriving a new object and overloading specific
>> operations for that object.  The base object isn't touched.
> 
> 
> And operations that are mistakenly not overridden become run-time errors.

Not if they're declared abstract. Then you have the same situation as 
missing cases for a variant record. Plus you don't have an escape like 
using "when others".

> 
>> Also: If the object is declared statically, the dispatching may happen
>> statically.
> 
> 
> This is true, but it seems that the nature of OP's problem would prevent 
> this.
> 



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

* Re: Conditional compilation in Ada?
  2004-11-18 15:17         ` Georg Bauhaus
@ 2004-11-18 19:12           ` Martin Dowie
  0 siblings, 0 replies; 47+ messages in thread
From: Martin Dowie @ 2004-11-18 19:12 UTC (permalink / raw)


"Georg Bauhaus" <sb463ba@l1-hrz.uni-duisburg.de> wrote in message 
news:cniedp$46g$1@a1-hrz.uni-duisburg.de...
> Martin Dowie <martin.dowie@btopenworld.com> wrote:
>
> : I've seen compilers that do this for the variant record method (most 
> seem to
> : in my experience) - is this true for the OO method?
>
> Do you mean, the OO method with dispatching calls?

I mean the OO method as descibed in this thread - i.e. do compilers _really_ 
understand when there will only be one derivation and not two or more.

-- Martin 





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

* Re: Conditional compilation in Ada?
  2004-11-18 15:23       ` Georg Bauhaus
@ 2004-11-18 22:10         ` Brian May
  2004-11-19  9:03           ` Martin Krischik
  2004-11-20  1:05         ` Conditional compilation in Ada? Dr. Adrian Wrigley
  1 sibling, 1 reply; 47+ messages in thread
From: Brian May @ 2004-11-18 22:10 UTC (permalink / raw)


>>>>> "Georg" == Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de> writes:

    Georg> pragma Ignore (

What is pragma ignore? I looked in the ARM but couldn't find it.
-- 
Brian May <bam@snoopy.apana.org.au>



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

* Re: Conditional compilation in Ada?
  2004-11-18 18:03         ` Alex R. Mosteo
@ 2004-11-19  3:00           ` Steve
  2004-11-19 21:35             ` Simon Wright
  0 siblings, 1 reply; 47+ messages in thread
From: Steve @ 2004-11-19  3:00 UTC (permalink / raw)


"Alex R. Mosteo" <devnull@mailinator.com> wrote in message
news:419CE3F5.6010906@mailinator.com...
[snip]
> >
> > And operations that are mistakenly not overridden become run-time
errors.
>
> Not if they're declared abstract. Then you have the same situation as
> missing cases for a variant record. Plus you don't have an escape like
> using "when others".
>

Actually in Ada I don't believe there is anything keeping you from declaring
an instance of an object that has abstract methods (unlike C++).  That was
my recollection, I created a small test program to verify and that was my
result.

Steve
(The Duck)

> >
> >> Also: If the object is declared statically, the dispatching may happen
> >> statically.
> >
> >
> > This is true, but it seems that the nature of OP's problem would prevent
> > this.
> >





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

* Re: Conditional compilation in Ada?
  2004-11-18 22:10         ` Brian May
@ 2004-11-19  9:03           ` Martin Krischik
  2004-11-20 17:31             ` Georg Bauhaus
  2004-12-12  0:17             ` How to switch off those damm warnings about unknows pragma Lionel Draghi
  0 siblings, 2 replies; 47+ messages in thread
From: Martin Krischik @ 2004-11-19  9:03 UTC (permalink / raw)


Brian May wrote:

>>>>>> "Georg" == Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de> writes:
> 
>     Georg> pragma Ignore (
> 
> What is pragma ignore? I looked in the ARM but couldn't find it.

Well that is the Trick - any Pragma which the compiler does not know is
ignored.  A pragma which no compiler knows about is ignored by all.

The thing I which for is a pragma to switch off the damm warning about not
knowing pragma X.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



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

* Re: Conditional compilation in Ada?
@ 2004-11-19  9:13 Christoph Karl Walter Grein
  0 siblings, 0 replies; 47+ messages in thread
From: Christoph Karl Walter Grein @ 2004-11-19  9:13 UTC (permalink / raw)
  To: comp.lang.ada

> Actually in Ada I don't believe there is anything keeping you from declaring
> an instance of an object that has abstract methods (unlike C++).  That was
> my recollection, I created a small test program to verify and that was my
> result.
> 
> Steve
> (The Duck)

package x is

  type t is tagged null record;

  procedure p(x:t) is abstract;

end x;

11:02:28 >>> Line 5: procedure P (X : T) is abstract;
11:02:28 *** An abstract subprogram shall not be a primitive subprogram of a non-abstract tagged type [RM_95 3.9.3(3)]

________________________________________________________________
Verschicken Sie romantische, coole und witzige Bilder per SMS!
Jetzt neu bei WEB.DE FreeMail: http://freemail.web.de/?mc=021193




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

* Re: Conditional compilation in Ada?
  2004-11-19  3:00           ` Steve
@ 2004-11-19 21:35             ` Simon Wright
  2004-11-20  2:56               ` Steve
  0 siblings, 1 reply; 47+ messages in thread
From: Simon Wright @ 2004-11-19 21:35 UTC (permalink / raw)


"Steve" <nospam_steved94@comcast.net> writes:

> "Alex R. Mosteo" <devnull@mailinator.com> wrote in message
> news:419CE3F5.6010906@mailinator.com...
> [snip]
> > >
> > > And operations that are mistakenly not overridden become run-time
> errors.
> >
> > Not if they're declared abstract. Then you have the same situation as
> > missing cases for a variant record. Plus you don't have an escape like
> > using "when others".
> >
> 
> Actually in Ada I don't believe there is anything keeping you from
> declaring an instance of an object that has abstract methods (unlike
> C++).  That was my recollection, I created a small test program to
> verify and that was my result.

Sounds like a buggy compiler! suggest you have another go ..

-- 
Simon Wright                               100% Ada, no bugs.



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

* Re: Conditional compilation in Ada?
  2004-11-18 15:23       ` Georg Bauhaus
  2004-11-18 22:10         ` Brian May
@ 2004-11-20  1:05         ` Dr. Adrian Wrigley
  2004-11-20 17:25           ` Georg Bauhaus
  2004-11-23  1:15           ` Arthur Schwarz
  1 sibling, 2 replies; 47+ messages in thread
From: Dr. Adrian Wrigley @ 2004-11-20  1:05 UTC (permalink / raw)


> pragma Ignore ( -- compiler warning 
>  DEBUG.put_line
>  (  "Here " & Is.Something ("reasonable complex to evaluate")
>  )
> );

Maybe I'm being stupid, but how does this help?
Doesn't this always have no effect?

I'd like to switch debugging on/off without editing every
DEBUG statement in the source...
-- 
Adrian




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

* Re: Conditional compilation in Ada?
  2004-11-19 21:35             ` Simon Wright
@ 2004-11-20  2:56               ` Steve
  2004-11-20 16:57                 ` Simon Wright
  0 siblings, 1 reply; 47+ messages in thread
From: Steve @ 2004-11-20  2:56 UTC (permalink / raw)


Several years ago on this newsgroup there was a thread discussing tagged
types with abstract methods.  In the discussion I was suprised to hear that
it was permissible to declare an instance of a type having abstract methods.
It kind of stuck in my mind.

I tried searching google groups for a reference to the original thread and
couldn't find it.  It may have had something to do with dispatching on
access types (?).

Prior to reading about it here, I had assumed that it was not possible to
create an instance of an object with abstract methods.  If that proves to be
the case, I think its a good thing.

Steve
(The Duck)


"Simon Wright" <simon@pushface.org> wrote in message
news:x7vvfc1bjy9.fsf@smaug.pushface.org...
> "Steve" <nospam_steved94@comcast.net> writes:
>
> > "Alex R. Mosteo" <devnull@mailinator.com> wrote in message
> > news:419CE3F5.6010906@mailinator.com...
> > [snip]
> > > >
> > > > And operations that are mistakenly not overridden become run-time
> > errors.
> > >
> > > Not if they're declared abstract. Then you have the same situation as
> > > missing cases for a variant record. Plus you don't have an escape like
> > > using "when others".
> > >
> >
> > Actually in Ada I don't believe there is anything keeping you from
> > declaring an instance of an object that has abstract methods (unlike
> > C++).  That was my recollection, I created a small test program to
> > verify and that was my result.
>
> Sounds like a buggy compiler! suggest you have another go ..
>
> -- 
> Simon Wright                               100% Ada, no bugs.





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

* Re: Conditional compilation in Ada?
  2004-11-20  2:56               ` Steve
@ 2004-11-20 16:57                 ` Simon Wright
  0 siblings, 0 replies; 47+ messages in thread
From: Simon Wright @ 2004-11-20 16:57 UTC (permalink / raw)


"Steve" <nospam_steved94@comcast.net> writes:

> Prior to reading about it here, I had assumed that it was not possible to
> create an instance of an object with abstract methods.  If that proves to be
> the case, I think its a good thing.

See http://www.adaic.org/standards/95aarm/html/AA-3-9-3.html -- in
particular, (3) says that if the operation is abstract so must the
type be, (1) says there can't be objects of abstract types.

-- 
Simon Wright                               100% Ada, no bugs.



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

* Re: Conditional compilation in Ada?
  2004-11-20  1:05         ` Conditional compilation in Ada? Dr. Adrian Wrigley
@ 2004-11-20 17:25           ` Georg Bauhaus
  2004-11-23  1:15           ` Arthur Schwarz
  1 sibling, 0 replies; 47+ messages in thread
From: Georg Bauhaus @ 2004-11-20 17:25 UTC (permalink / raw)


Dr. Adrian Wrigley wrote:
>>pragma Ignore ( -- compiler warning 
>> DEBUG.put_line
>> (  "Here " & Is.Something ("reasonable complex to evaluate")
>> )
>>);
> 
> 
> Maybe I'm being stupid, but how does this help?
> Doesn't this always have no effect?

That's right, it doesn't solve the original problem without
a compiler mechanism like -gnata and pragma Debug in GNAT.
I mentioned this in a rush to show Dmitry a way to have
lazy evaluation in Ada. ;-)

Georg



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

* Re: Conditional compilation in Ada?
  2004-11-19  9:03           ` Martin Krischik
@ 2004-11-20 17:31             ` Georg Bauhaus
  2004-11-21  9:14               ` Martin Krischik
  2004-12-12  0:36               ` Lionel Draghi
  2004-12-12  0:17             ` How to switch off those damm warnings about unknows pragma Lionel Draghi
  1 sibling, 2 replies; 47+ messages in thread
From: Georg Bauhaus @ 2004-11-20 17:31 UTC (permalink / raw)


Martin Krischik wrote:
 
> The thing I which for is a pragma to switch off the damm warning about not
> knowing pragma X.

As another example, I also have pragma TODO[(...)];
in my sources. I definitely want a compiler warning for these.

You'd have to have a pragma to turn off the warnings about
a pragma ... ;-) Or something in the project file.
I think it's better to write source code that doesn't
produce (too many) warnings because it is correct. If the
sources are not to be trusted yet, I just live with the warnings.
They are good reminders.


Georg



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

* Re: Conditional compilation in Ada?
  2004-11-20 17:31             ` Georg Bauhaus
@ 2004-11-21  9:14               ` Martin Krischik
  2004-12-12  0:36               ` Lionel Draghi
  1 sibling, 0 replies; 47+ messages in thread
From: Martin Krischik @ 2004-11-21  9:14 UTC (permalink / raw)


Georg Bauhaus wrote:

> Martin Krischik wrote:
>  
>> The thing I which for is a pragma to switch off the damm warning about
>> not knowing pragma X.
> 
> As another example, I also have pragma TODO[(...)];
> in my sources. I definitely want a compiler warning for these.
> 
> You'd have to have a pragma to turn off the warnings about
> a pragma ... ;-) Or something in the project file.
> I think it's better to write source code that doesn't
> produce (too many) warnings because it is correct. If the
> sources are not to be trusted yet, I just live with the warnings.
> They are good reminders.

You are right. but pragmas are a special case. I remember the time when
AdaCL was less the 37 packages and I keeps it compatible with the Aonix
compiler.

ObjectAda did not know about  "pragma Unreferenced" and would produce a
warning every time. And I had a lot of "pragma Unreferenced (Trace);".
[Trace is a controlled object created only for tracking function enty and
exit points]

I could use my trace facility without pragma Unreferenced but then GNAT
would produce warnings about unreferenced objects. 

Eventualy AdaCL reached the 37 package limit and the problem solved itself -
I droped ObjectAda support.

With Regards

Martin

PS: 
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



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

* Re: Conditional compilation in Ada?
  2004-11-20  1:05         ` Conditional compilation in Ada? Dr. Adrian Wrigley
  2004-11-20 17:25           ` Georg Bauhaus
@ 2004-11-23  1:15           ` Arthur Schwarz
  2004-11-23 15:42             ` skidmarks
  1 sibling, 1 reply; 47+ messages in thread
From: Arthur Schwarz @ 2004-11-23  1:15 UTC (permalink / raw)


Dr. Adrian Wrigley wrote:
>>pragma Ignore ( -- compiler warning 
>> DEBUG.put_line
>> (  "Here " & Is.Something ("reasonable complex to evaluate")
>> )
>>);
> 
> 
> Maybe I'm being stupid, but how does this help?
> Doesn't this always have no effect?
> 
> I'd like to switch debugging on/off without editing every
> DEBUG statement in the source...

Same problem. What I usually do is use a flexible scheme to represent 
debug flags. If I want the code permanantly removed, I set the debug 
flags to:

     Debug_Flag : constant Boolean := FALSE;

and if I want the conde permanently available, I set the debug flags to:

     Debug_Flag : constant Boolean := TRUE;

and if I want to (interactive) change my mind, I set the debug flags to:

     Debug_Flag : Boolean := TRUE;

The pragma inline (below) conserves code and enables identification of 
debug sections - it is for a maintainer's notification and does nothing 
in terms of code or code integrity. And I know, I know, 'pragma inline' 
is only a suggestion to the compiler - but a good one.

The Is_Debug functions are tailored to suit. I've given only a clear (?) 
and simple presentation of principle.

Forgive the Ada.

Hope this provides a focus for conversation. It would be nice to see 
what debug things are out their.

art


Package one body is

Debug_Flag  : Boolean := TRUE;  // Note: this is a variable
                                 // and placed in the spec file.

function Is_Debug return Boolean is
begin -- Is_Debug
    return Debug_Flag;
end Is_Debug;
pragma inline( Is_Debug );


end one;

Package two body is

Debug_Flag  : Boolean := TRUE; // same as above

function Is_Debug return boolean is
begin -- Is_Debug
    return Debug_Flag and one.Is_Debug;
end Is_Debug;


procedure Some_Thing is
begin -- Some_Thing
    if ( Is_Debug ) then
      null;
    end if;
end Some_Thing;
end two;




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

* Re: Conditional compilation in Ada?
  2004-11-23  1:15           ` Arthur Schwarz
@ 2004-11-23 15:42             ` skidmarks
  0 siblings, 0 replies; 47+ messages in thread
From: skidmarks @ 2004-11-23 15:42 UTC (permalink / raw)


> 
> 
> Package one body is
> 
> Debug_Flag  : Boolean := TRUE;  // Note: this is a variable
>                                  // and placed in the spec file.
> 
> function Is_Debug return Boolean is
> begin -- Is_Debug
>     return Debug_Flag;
> end Is_Debug;
> pragma inline( Is_Debug );
> 

Sorry. I just read the original post. The advantage of using constants
is that the compiler (should) remove the conditional branch which is
never executed, viz.

     Debug_Flag := constant Boolean := TRUE;

     if ( Debug_Flag ) then null; // always executed
                       else null; // never executed and the compiler
will
     end if;                      // remove the code

The function 'Is_Debug' with a pragma inline should have the same
effect.

Since the flag conditions the branch, it is possible to compile all
required code variants and select them at run-time by using a variable
flag instead of a constant. If you are willing to perform multiple
builds, then a constant flag achieves much the same effect as a C/C++
conditional compilation. And, of course, the Is_Debug is thrown in as
a 'plus'.

art



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

* How to switch off those damm warnings about unknows pragma
  2004-11-19  9:03           ` Martin Krischik
  2004-11-20 17:31             ` Georg Bauhaus
@ 2004-12-12  0:17             ` Lionel Draghi
  2004-12-13 11:10               ` Georg Bauhaus
  2004-12-13 15:07               ` Peter Amey
  1 sibling, 2 replies; 47+ messages in thread
From: Lionel Draghi @ 2004-12-12  0:17 UTC (permalink / raw)


Martin Krischik a �crit :
...
> The thing I which for is a pragma to switch off the damm warning about not
> knowing pragma X.

I strongly agree. We do use handy GNAT specific pragma, and they cause 
lots of spurious warning when compiling with ObjectAda. Filtering those 
useless warning is a pain.

But even before adding a new pragma to the language, I asked to myself 
why compiler vendors don't provide a compile option to ignore a 
(precise) list of pragmas. I suppose it's a simple change in compilers code.

My hypothesis is that:
- vendors don't wan't to ease the life of customers using competitor's 
product :-)
- most Ada programs are compiled for a single platform
- most of those compiled for more platform are with the same compiler
- most of those compiled with several compiler or for several platform 
are when migrating from one to another, and don't actually target them 
simultaneously
Let's now remove from the few remaining those using no specific pragma, 
and those who don't read warnings :-), and there is almost no customer 
in the world for seach a feature!

Anyway, we are at least two :-)

-- 
Lionel Draghi



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

* Re: Conditional compilation in Ada?
  2004-11-20 17:31             ` Georg Bauhaus
  2004-11-21  9:14               ` Martin Krischik
@ 2004-12-12  0:36               ` Lionel Draghi
  1 sibling, 0 replies; 47+ messages in thread
From: Lionel Draghi @ 2004-12-12  0:36 UTC (permalink / raw)


Georg Bauhaus a écrit :
...
> As another example, I also have pragma TODO[(...)];
> in my sources. I definitely want a compiler warning for these.

Thank you for the tip.

Considering that TODO comments are so easy to forget in the code, and 
that explicitly raising an exception "Remember_This" is not a solution 
(especially if the program is delived :-), I like your idea!

-- 
Lionel Draghi



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

* Re: How to switch off those damm warnings about unknows pragma
  2004-12-12  0:17             ` How to switch off those damm warnings about unknows pragma Lionel Draghi
@ 2004-12-13 11:10               ` Georg Bauhaus
  2004-12-13 15:07               ` Peter Amey
  1 sibling, 0 replies; 47+ messages in thread
From: Georg Bauhaus @ 2004-12-13 11:10 UTC (permalink / raw)


Lionel Draghi <Lionel.nospam.Draghi@ada-france.org> wrote:
 
: But even before adding a new pragma to the language, I asked to myself 
: why compiler vendors don't provide a compile option to ignore a 
: (precise) list of pragmas. I suppose it's a simple change in compilers code.

Maybe filtering is already possible. Using IDEs like Emacs, GPS,
(Aonix is working on Eclipse integragtion I believe) compiler output
is processed anyways. So you could set up a grammer or regular expression
describing the set of unwanted warnings. The have the IDE move the
warnings out of sight.


-- Georg



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

* Re: How to switch off those damm warnings about unknows pragma
  2004-12-12  0:17             ` How to switch off those damm warnings about unknows pragma Lionel Draghi
  2004-12-13 11:10               ` Georg Bauhaus
@ 2004-12-13 15:07               ` Peter Amey
  1 sibling, 0 replies; 47+ messages in thread
From: Peter Amey @ 2004-12-13 15:07 UTC (permalink / raw)




Lionel Draghi wrote:
[snip]
> 
> But even before adding a new pragma to the language, I asked to myself 
> why compiler vendors don't provide a compile option to ignore a 
> (precise) list of pragmas. I suppose it's a simple change in compilers 
> code.

Doesn't help you with compilers, but the "precise list of pragmas to be 
ignored" is exactly the mechanism we use in the SPARK Examiner.  We 
chose this route because the Examiner must work with all compilers and 
we are very keen to keep the signal to noise ratio of our analysis as 
high as possible.

>[snip]


Peter




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

end of thread, other threads:[~2004-12-13 15:07 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-16 18:30 Conditional compilation in Ada? jtg
2004-11-16 18:45 ` Marius Amado Alves
2004-11-16 20:41   ` Nick Roberts
2004-11-17  8:36     ` Alex R. Mosteo
2004-11-16 19:03 ` Jeffrey Carter
2004-11-16 19:13   ` Hyman Rosen
2004-11-16 19:41     ` Björn Lundin
2004-11-16 20:08     ` tmoran
2004-11-16 20:27       ` Hyman Rosen
2004-11-16 23:49         ` Jim Rogers
2004-11-16 20:43     ` Martin Dowie
2004-11-16 19:06 ` tmoran
2004-11-17  9:39   ` Adrien Plisson
2004-11-17 16:39     ` Jacob Sparre Andersen
2004-11-17  2:44 ` Steve
2004-11-17 20:30   ` Jeffrey Carter
2004-11-18  4:09     ` Steve
2004-11-18  6:49       ` Martin Dowie
2004-11-18 15:17         ` Georg Bauhaus
2004-11-18 19:12           ` Martin Dowie
2004-11-18 17:34         ` Jeffrey Carter
2004-11-18 17:44       ` Jeffrey Carter
2004-11-18 18:03         ` Alex R. Mosteo
2004-11-19  3:00           ` Steve
2004-11-19 21:35             ` Simon Wright
2004-11-20  2:56               ` Steve
2004-11-20 16:57                 ` Simon Wright
2004-11-17  9:28 ` Martin Krischik
2004-11-17 13:39   ` Stephen Leake
2004-11-17 10:02 ` Frank Piron
2004-11-17 12:32   ` Georg Bauhaus
2004-11-17 14:44     ` Dmitry A. Kazakov
2004-11-18 15:23       ` Georg Bauhaus
2004-11-18 22:10         ` Brian May
2004-11-19  9:03           ` Martin Krischik
2004-11-20 17:31             ` Georg Bauhaus
2004-11-21  9:14               ` Martin Krischik
2004-12-12  0:36               ` Lionel Draghi
2004-12-12  0:17             ` How to switch off those damm warnings about unknows pragma Lionel Draghi
2004-12-13 11:10               ` Georg Bauhaus
2004-12-13 15:07               ` Peter Amey
2004-11-20  1:05         ` Conditional compilation in Ada? Dr. Adrian Wrigley
2004-11-20 17:25           ` Georg Bauhaus
2004-11-23  1:15           ` Arthur Schwarz
2004-11-23 15:42             ` skidmarks
2004-11-17 12:27 ` Marin David Condic
  -- strict thread matches above, loose matches on Subject: below --
2004-11-19  9:13 Christoph Karl Walter Grein

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