Thanks,
Ken Kueny
No, Ada does not have conditional compilation. When the language was
being designed, conditional compilation was expressly prohibited (for
very good reason).
There's a good discussion of this in one of our old FAQs at
http://www.adahome.com/FAQ/programming.html#macros . I'd repost it here,
but unfortunately the text is copyrighted. :-(
--
T.E.D.
http://www.telepath.com/~dennison/Ted/TED.html
Sent via Deja.com http://www.deja.com/
Before you buy.
Yes. We write package specifications and have different implementations
(bodies) for different versions.
--
Jeff Carter
"Son of a silly person."
Monty Python & the Holy Grail
No. IIRC, the usual method is to make seperate bodies for the different
versions, and only compile the one you want to use. Alternately, you
can use the preprocessor of your choice on the code - gnatprep comes
with GNAT, or you can use M4 or some other generic preprocessor. (I've
heard cpp has problems with the ' attribute syntax, though.)
--
David Starner - dstar...@aasaa.ofe.org
http/ftp: dvdeug.dhis.org
And crawling, on the planet's face, some insects called the human race.
Lost in space, lost in time, and meaning.
-- RHPS
Kenneth Kueny wrote:
> Does ADA have an analog to the C language #define, #ifdef constructs
> commonly used to include or exclude certain blocks of code in different code
> versions?
That is not as stupid a question as some habitues of this forum might assume. I
recall
a project in the late 1980's where the Ada 83 code was targeted to an embedded
processor. The compiler for the intended deployment was priced very high "per
seat." This was a non-DoD project with a requirement for a lot of programmers
and there was a need to stay within a reasonable budget.
The development manager bought a lot of copies of the Meridian compiler for the
programmers and let each have a copy for his/her home computer, and installed it
on MS-DOS based computers all over the lab. Then, one of the programmers wrote
a little preprocessor program to detect the difference between code for the
Meridian
compiler and the expensive embedded system compiler. This was done with a
commenting scheme in which the double hyphen, followed by some identifiers could
tell the difference between the two compilation environments.
The preprocessor would simply remove comments as appropriate for whichever
compiler was
being used. There was code in the Meridian version to emulate the features
required by the
embedded compiler. Programmers were encouraged to write vanilla-flavored Ada
as much
as possible to avoid the issues related to the embedded compiler. As is
typical of such
development, much of the platform-dependent code was pushed to a low level of
abstraction.
One result was that the programmers, encouraged to use Ada for more than just
their daily work,
were willing to experiment with it on their own time. More important, the
developer did not have
to buy as many copies of the expensive compiler, thereby reducing their overall
costs. The downside
was that the publisher of the embedded compiler experienced financial
difficulties and is
no longer able to supply Ada compilers for newer products manufactured by this
organization.
As far as I know, the manufacturer continues to quietly use Ada for its embedded
non-Dod
software products, but now provides GNAT instead of Meridian. Rational dropped
the idea
of updating Meridian to Ada 95 and missed an opportunity to provide a low-cost
commercial
Ada 95 compiler that could compete with GNAT.
Preprocessors, such as the one just described, may not be in the best economic
interest
of the embedded compiler publishers since those publishers end up selling fewer
licences.
For a commercial manufacturer using Ada, this kind preprocessor may have the
benefit of
making the development effort a little more profitable.
Richard Riehle
ric...@adaworks.com
> Does ADA have an analog to the C language #define, #ifdef constructs
> commonly used to include or exclude certain blocks of code
> in different code versions?
This is a bit confusing.
The C macro preprocessor wasn't originally part
of the C computer programming language.
It was, and still is, a separate program
which accepted a C program "source file"
and emitted a C program "translation unit".
The typical C compiler accepts a translation unit
and compiles it into assembly language code
then calls the assembler to generate machine code.
The ANSI/ISO C/C++ standards now specify
syntax and semantics for the C macro preprocessor
but you can still use the C macro preprocessor
on Ada source files as long as the translation unit
is an acceptable Ada program.
Try it. It works.
Now, professional programmers almost never write
programs in Ada, C, C++ or any other standard
computer programming language directly.
They usually use perl, the m4 macro preprocessor,
the sed stream editor or some combination of tools
to write programs for them from "prototype files"
which they maintain instead of source files.
Of course, if you are distributing "open source" programs,
you will need to distribute the prototype files
and any special tools along with the source files
so that other programmers can help to maintain
an contribute to the prototype files as well.
> The typical C compiler accepts a translation unit
> and compiles it into assembly language code
> then calls the assembler to generate machine code.
> Now, professional programmers almost never write
> programs in Ada, C, C++ or any other standard
> computer programming language directly.
> They usually use perl, the m4 macro preprocessor,
> the sed stream editor or some combination of tools
> to write programs for them from "prototype files"
> which they maintain instead of source files.
You live in a strange different world !!!
You sure? It was definetly a part of K&R C, and it would be almost
impossible to build a C program without it.
>but you can still use the C macro preprocessor
>on Ada source files as long as the translation unit
>is an acceptable Ada program.
>Try it. It works.
Maybe. cpp will emit errors about unterminted character constants,
it will chop up C comments, and do other unfriendly things. It
can work, but I'm not sure it's a great idea.
>Now, professional programmers almost never write
>programs in Ada, C, C++ or any other standard
>computer programming language directly.
>They usually use perl, the m4 macro preprocessor,
>the sed stream editor or some combination of tools
>to write programs for them from "prototype files"
Not that I've seen. For example, GCC and GNAT use prototype files
for machine descriptions, but for pretty much everything else
it's just straight code. moc (QT's preprocessor) is about the only
largescale example of that I've seen.
Larry Kilgallen wrote:
>
> In article <39C7C748...@netwood.net>, "E. Robert Tisdale" <ed...@netwood.net> writes:
>
> > The typical C compiler accepts a translation unit
> > and compiles it into assembly language code
> > then calls the assembler to generate machine code.
>
> > Now, professional programmers almost never write
> > programs in Ada, C, C++ or any other standard
> > computer programming language directly.
> > They usually use perl, the m4 macro preprocessor,
> > the sed stream editor or some combination of tools
> > to write programs for them from "prototype files"
> > which they maintain instead of source files.
>
> You live in a strange different world !!!
It was humor!!!
Could we please get a more informative answer.
The above does NOT address the question and does
NOT cover the problem space inferred by the questioner!
--
Samuel T. Harris, Principal Engineer
Raytheon, Aerospace Engineering Services
"If you can make it, We can fake it!"
> For example, I heard high up people in the DoD in charge of
> information processing systems seriously claim that no one
> would do any more programming any more, we would simply
> put our "business models" into the 4GL tool and that would
> be it :-)
Yeah, heard a lot of that in the trade media 10 years ago.
Meanwhile, I worked for a PHB who complained that our reports showed
that the "pounds ordered" and "pounds shipped" last month didn't match,
so their must be a bug in our programs. Proving once and for all that
even if 4GLs, 5GLs, 9GLs, or whatever, are eventually operable by PHBs,
they'll *still* need programmers as an interface between the Management
Zone and reality.
Bobby Bryant
Austin, Texas
Well it does relate to the *problem* space, which is to
provide for different versions of the program for different
circumstances. It does not relate the the specific *solution*
space suggested by the questioner, which was to solve this
problem with conditional compilation. In fact many people feel
that conditional compilation is the wrong way to go about
this kind of specialization. This is of course an old and
weary discussion. It is hard to believe that anything new
can come from spinning this thread once more :-)
Well almost, the requirement of valid C tokens causes
trouble with constructions like Integer'Val (x)!
> Now, professional programmers almost never write
> programs in Ada, C, C++ or any other standard
> computer programming language directly.
> They usually use perl, the m4 macro preprocessor,
> the sed stream editor or some combination of tools
> to write programs for them from "prototype files"
> which they maintain instead of source files.
In fact the percentage of programming done this way,
particularly in large Ada programs, is quite small, and
the applicability of such techniques is quite limited.
The "almost never" in the above paragraph is a huge
exaggeration.
Ah, but we really have a hard time identifying it as humour,
because you can easily find this type of viewpoint expressed
seriously.
For example, I heard high up people in the DoD in charge of
information processing systems seriously claim that no one
would do any more programming any more, we would simply
put our "business models" into the 4GL tool and that would
be it :-)
Anyway, do us a favor, this is a strange field, and we cannot
conclude that just because somone is saying something ludicrous
that they intend it as a joke. So please add a smiley, otherwise
you are likely to be confused with people who really believe
some lunatic ideas :-)
The C preprocessor is most certainly part of C, and the fact
that it may be implemented as a separate program is not
relevant (except that, as noted, it may mean that in practice
it can be used for other languages).
Note that there are other possibilities, including
generalized macro processors (some of the GNAT tasking
development was originally done using the M4 processor).
specialized Ada preprocessing tools. GNAT supplies a tool
called gnatprep, and you will find that other vendors have
similar tools. In fact gnatprep is really pretty much
independent of GNAT and could be used with any Ada compiler.
(or for that matter, any C compiler :-)
No and that is nice. The problem as I see it with #define and #ifdef is
that they mess up the "flow of the code" for the reader. That is it is
hard enough to follow C code and even harder when you also have to take
into account the different #ifdefs
The Ada (notice the spelling, i.e not ADA) way is to build packages
that contains the different parts.
Look at: http://www.tc.umn.edu/~puk/tetris.txt for an simple example.
Please note that all the packages are put into a txt file. They would
have to be put into different files if you wanted to compile it. I think
there was a zip package out there with the files, but I cannot find it.
If you want a copy send me an e-mail as I have alread split them myself.
--
Preben Randhol - Ph.D student - http://www.pvv.org/~randhol/
"i too once thought that when proved wrong that i lost somehow"
- i was hoping, alanis morisette
Of course the drawback to this approach is that both alternatives have
to be compilable. That makes it suitable for debug messages (as implied
above), but unsuitable for making a source file that handles multiple
host configurations.
Also, the only method that (standard) Ada allows for you to change the
value of Debug_Version before the compile is to edit the source file
manually. That could be automated in your software build facility using
various tools, but it would be just as easy to have two different source
files for the build facility to choose between.
Many Ada compilers come with a (non-standard) precompiler or conditional
compilation macros. If you have a *legitimate* need for conditionally
compiled code, you may want to check your compiler docs to see. But if
you are learning Ada, I'd council that you avoid such features. You need
to learn Adado (the Ada way) first, or you will likly end up spending
the whole project fighting the language.
--
T.E.D.
http://www.telepath.com/~dennison/Ted/TED.html
I did not say it was not related.
I said it does not cover the problem space.
Handling variant package bodies can only get you so far.
Sometimes the differences are in the specification.
Sometimes the amount of variant code is so trivial
in comparison to the size of the entire project that
the configuration management issues to support separate
content is simply not worth the trouble.
As to my personal preference, I tend to side with
variant content as separate content, but then I've
been doing it so long it is simply second nature to me.
But I do understand the viewpoint of wanting to avoid
separate files for similar things.
> But I do understand the viewpoint of wanting to avoid
> separate files for similar things.
The important thing to remember is that the original question wasn't
"Are the #define, #ifdef statements good things to have?" The original
question was: "Does Ada have an equivalent to #define, #ifdef, etc.?"
The answer, of course, is "No". I would agree that they are not the only
way or the best way of managing divergent paths of code, but as you
imply, there may be reasons to want it done this way.
Maybe this is a good topic for the FAQ. It seems to spark occasional
long threads of sometimes religious debate. :-)
--
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at: http://www.mcondic.com/
"Take away the punchbowl just when the party gets going"
-- William McChesney Martin, Former Fed chairman, explaining
what a sound central bank must always do.
======================================================================
> Maybe this is a good topic for the FAQ. It seems to spark occasional
> long threads of sometimes religious debate. :-)
I agree completely. I started to add it, but it turns out that there's a
major revision of the FAQ on the way so I'm holding off for now. In the
meantime it would be helpful if those who answer this thread would consider
giving permission to have all or part of their posting GPL'ed for the FAQ.
Of course you will be consulted first.
The old FAQ entry on AdaHome was actually quite good on this subject. It
might have stopped this whole thread cold if I could have posted it. But its
copyrighted, which is why we have to make a new FAQ. It looks like the
license might allow me to post the *entire* FAQ, but I don't think that
would have helped.
BTW: I remember that Magnus generally just slammed the text of other
people's postings together into his FAQ entries. So for those of you who
have been here for several years, I'd appreciate it if you would go to the
old programming FAQ entry at
http://www.adahome.com/FAQ/programming.html#macros and see if any of the
text there was yours. If it was, and I can verify that through deja, then
with your permission it could be put in the new FAQ.
In fact, it would be a good idea for everyone to do that for *all* the old
FAQ entries. That might help get the new FAQ effort off to a good running
start.
--
T.E.D.
Home - mailto:denn...@telepath.com
WWW - http://www.telepath.com/dennison/Ted/TED.html
(I KNOW I'm gonna get flamed on THIS one!)
John
Kenneth Kueny wrote:
> Does ADA have an analog to the C language #define, #ifdef constructs
> commonly used to include or exclude certain blocks of code in different code
> versions?
>
> Thanks,
>
> Ken Kueny
--
That would be my choice also. Or even better, have the Apex RCI set up
for your target compiler and hardware and then you can do the target
builds completely from Apex. We are currently getting that setup.
Right now I use special comment characters in the files for host
specific lines and use a perl script to swap them for the target
version - this way there is only one version of the file in Apex to
maintain and when you use the 'visit' feature, you end up in this
file and can see the target code as well as the host version.
Jerry
Here's a horrible thought: You know how dumb the average person is?
Well, half the human race is even dumber than that...
-----------------------------------------------------------------------------
-- Jerry Petrey
-- Senior Principal Systems Engineer - Member Team Ada & Team Forth
-- Raytheon Missile Systems
-- NOTE: please remove NOSPAM in email address to reply
-----------------------------------------------------------------------------
: Why not use Rational Apex for Ada, place the different code blocks
: (or separate bodies) in different segments / views, use import/export,
: and "builds" to create and manage various versions?
Well then, let me throw in literate programming tools
with all their drawbacks. Here they shine. And are
a bit more affordable. :-)
Well... aren't you confusing the average with the median... :-)
--
---------------------------------------------------------
J-P. Rosen (Rosen....@wanadoo.fr)
Visit Adalog's web site at http://pro.wanadoo.fr/adalog
>Larry Kilgallen wrote:
>> "E. Robert Tisdale" <ed...@netwood.net> writes:
>> > The typical C compiler accepts a translation unit
>> > and compiles it into assembly language code
>> > then calls the assembler to generate machine code.
>> > Now, professional programmers almost never write
>> > programs in Ada, C, C++ or any other standard
>> > computer programming language directly.
>> > They usually use perl, the m4 macro preprocessor,
>> > the sed stream editor or some combination of tools
>> > to write programs for them from "prototype files"
>> > which they maintain instead of source files.
>> You live in a strange different world !!!
>It was humor!!!
Not where I work it isn't. The model of dynamic web page serving is
prototypes and tools that plug stuff into predefined slots in those
prototypes. We have somewhat over 10,000 working prototype instances
to prove the concept viable. Let's don't mention sensible, OK?
xanthian.
===== random archival quality quote =====
It used to be that I could rely on [my Magic 8-Ball of Destiny] to
predict the future for me, particularly with regard to answering
annoying Project Manager questions, like: "How many calendar weeks
do you think it will take to finish this project we have you working
on starting in December, which is minimally equal in scope to the
Apache Web Server project, and yes we understand that you have no
marketing requirements for it yet at all, and you have no idea how
many people we'll be able to assign to the project, but pretend
none of that is important -- we need to know when you'll be finished
with it?"
-- j h woodyatt <j...@wetware.com> <http://www.wetware.com/jhw>
--
Kent Paul Dolan.
<xant...@well.com> <xant...@aztec.asu.edu> <kdo...@ebay.com>
That's precisely what surprised me, the rest of the IS world
went through this illusion a decade ago, and has long since
recognized the reality of the situation :-)
Well in a way it is a big advantage that it all has to be
compilable. it is only too common to encouter a large C
file, full of conditional stuff based on say ten different
condition settings, and you just know that no one has
systematically done all 1024 compilations, and sure enough
you try a new combination, and the thing does not even compile,
let alone work.
Well in fact some variation of this is the normal Ada way
of doing things, and all Ada technologies support this kind
of approach.
Ohhh yeah. I wasted a weekend once trying to get Wolfpack's Empire to
compile on my NT box using gcc. It has a whole mess of conditional
compilation code which assumes Windows means VC++ is being used. That
combined with the macros that detect gcc and pull in other stuff just
wreaked holy hell. A few hours of that is enough to convince anyone that
the man who forbade macros from Ada was a genius.
Of course it was no picnic getting it to work with the newer version of
VC++ I had either. But that's another C gripe for another time.
--
T.E.D.
Home - mailto:denn...@telepath.com Work - mailto:denn...@ssd.fsi.com
WWW - http://www.telepath.com/dennison/Ted/TED.html ICQ - 10545591
I saw once some C code where a comment before start of a function said:
"Too large for a macro"
Later I learned that the programmer did everything in macros, and
only if they could not, resorted to functions.
The most fun was when seeing a macro using other macros. (some C
compiler would chock on this).
Saw one C file which had 7 different compilation modes, and overlays between
them. So complex, impossible to understand one mode from the other becuase
every other line there is an #ifdef this_mode || that_mode, so the only
way to understand the logic of each mode by itself, is to compile
using -E flag (with one -Dmode_name) and then look at the outout of
the pre-processor. one mode did not compile at all, it was missing
header files. Later I learned this mode was no longer supported (so dead code
sitting in there).
One of the things I like about java (as with Ada) is lack of macros
and pre-proccessor and everything that comes with that (i.e. the #define mess),
and lack of header files.
peter
>Now, professional programmers almost never write
>programs in Ada, C, C++ or any other standard
>computer programming language directly.
>They usually use perl, the m4 macro preprocessor,
>the sed stream editor or some combination of tools
>to write programs for them from "prototype files"
>which they maintain instead of source files.
That's news to me. If only I'd known that as a professional programmer
these last 13 years I could have saved myself some time!
Best Regards
John McCabe <jo...@assen.demon.co.uk>
No it does not and for good reasons.
But if you really need one - and we found we did - look at
http://users.swing.be/imw
Use with care, however.
For a complete explanation of what we were doing, come along to
Ada-Europe'2001 in May. About 14:30 on Thursday, all should be made
clear.
Andrew Hately
Eurocontrol
Most Ada systems will include a preprocessor, for example,
see gnatprep supplied with GNAT (whose design is copied
from widely used Ada 83 tools).