* How to compile Barnes' examples from his book using GNAT @ 2015-12-06 10:49 Jerry 2015-12-06 11:24 ` Brian Drummond 0 siblings, 1 reply; 12+ messages in thread From: Jerry @ 2015-12-06 10:49 UTC (permalink / raw) How does one compile Barnes' examples from his book, Programming in Ada 2012, with GNAT? The programs are available here: cambridge.org/barnes -> Resources -> Programs. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-06 10:49 How to compile Barnes' examples from his book using GNAT Jerry @ 2015-12-06 11:24 ` Brian Drummond 2015-12-06 18:17 ` Jeffrey R. Carter 2015-12-07 9:01 ` Jerry 0 siblings, 2 replies; 12+ messages in thread From: Brian Drummond @ 2015-12-06 11:24 UTC (permalink / raw) On Sun, 06 Dec 2015 02:49:23 -0800, Jerry wrote: > How does one compile Barnes' examples from his book, Programming in Ada > 2012, with GNAT? The programs are available here: cambridge.org/barnes > -> Resources -> Programs. It should be as simple as "gnatmake main_program.adb". In fact it isn't ... quite. Taking the first on that list, XPROG6.txt for example, I see that it has to be split into .ads files for each package, and matching .adb files for each package body and the main program. Tedious ... except there's a tool called "gnatchop" to do that. So, gnatchop XPROG6.txt gnatmake tower_of_hanoi.adb Job done. -- Brian ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-06 11:24 ` Brian Drummond @ 2015-12-06 18:17 ` Jeffrey R. Carter 2015-12-06 21:21 ` Pascal Obry 2015-12-07 9:01 ` Jerry 1 sibling, 1 reply; 12+ messages in thread From: Jeffrey R. Carter @ 2015-12-06 18:17 UTC (permalink / raw) On 12/06/2015 04:24 AM, Brian Drummond wrote: > > So, > gnatchop XPROG6.txt > gnatmake tower_of_hanoi.adb > > Job done. Almost. However, with no options, GNAT is not an Ada compiler. It doesn't insert integer-overflow checks, stack-overflow checks, assertion checks, pre- and post-condition checks, predicate checks, or invariant checks. The programs may behave differently without these checks than described in the book. In addition, it uses GNAT's static elaboration order rather than doing elaboration as described in the ARM. This shouldn't affect the behavior of the programs, though, so it's not really important. The options to include all the checks in the ARM are -gnatao -fstack-check The option to use ARM elaboration is -gnatE. Since we have to type options to get an Ada compiler, one might also want to use -gnatn -gnatwa -O2 to turn on cross-unit inlining, turn on all warnings, and perform some optimization. The available options are described in detail in the top-secret GNAT User's Guide: http://docs.adacore.com/gnat_ugn-docs/html/gnat_ugn/gnat_ugn.html -- Jeff Carter "I wave my private parts at your aunties." Monty Python & the Holy Grail 13 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-06 18:17 ` Jeffrey R. Carter @ 2015-12-06 21:21 ` Pascal Obry 2015-12-06 22:33 ` Jeffrey R. Carter 0 siblings, 1 reply; 12+ messages in thread From: Pascal Obry @ 2015-12-06 21:21 UTC (permalink / raw) Jeffrey, > Almost. However, with no options, GNAT is not an Ada compiler. It > doesn't insert > integer-overflow checks, Recent GNAT versions have overflow on by default. > stack-overflow checks, assertion checks, pre- and > post-condition checks, predicate checks, or invariant checks. The assertions and aspects checks are optional for an Ada compiler and can be turned on and off. -- Pascal Obry / Magny Les Hameaux (78) The best way to travel is by means of imagination http://v2p.fr.eu.org http://www.obry.net gpg --keyserver keys.gnupg.net --recv-key F949BD3B ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-06 21:21 ` Pascal Obry @ 2015-12-06 22:33 ` Jeffrey R. Carter 2015-12-08 2:01 ` Randy Brukardt 0 siblings, 1 reply; 12+ messages in thread From: Jeffrey R. Carter @ 2015-12-06 22:33 UTC (permalink / raw) On 12/06/2015 02:21 PM, Pascal Obry wrote: > >> Almost. However, with no options, GNAT is not an Ada compiler. It >> doesn't insert >> integer-overflow checks, > > Recent GNAT versions have overflow on by default. That's good. When I had checked not too long ago, it was still off by default. >> stack-overflow checks, assertion checks, pre- and >> post-condition checks, predicate checks, or invariant checks. > > The assertions and aspects checks are optional for an Ada compiler and > can be turned on and off. True, but examples from the book intended to demonstrate the use of these features may not behave as described if they are not turned on. -- Jeff Carter "I wave my private parts at your aunties." Monty Python & the Holy Grail 13 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-06 22:33 ` Jeffrey R. Carter @ 2015-12-08 2:01 ` Randy Brukardt 0 siblings, 0 replies; 12+ messages in thread From: Randy Brukardt @ 2015-12-08 2:01 UTC (permalink / raw) "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message news:n42cuc$nqs$1@dont-email.me... > On 12/06/2015 02:21 PM, Pascal Obry wrote: >> >>> Almost. However, with no options, GNAT is not an Ada compiler. It >>> doesn't insert >>> integer-overflow checks, >> >> Recent GNAT versions have overflow on by default. > > That's good. When I had checked not too long ago, it was still off by > default. > >>> stack-overflow checks, assertion checks, pre- and >>> post-condition checks, predicate checks, or invariant checks. >> >> The assertions and aspects checks are optional for an Ada compiler and >> can be turned on and off. > > True, but examples from the book intended to demonstrate the use of these > features may not behave as described if they are not turned on. I would guess that most people starting out would expect that the default would be for them to be on. I got caught by it writing ACATS tests. The main reason the language doesn't say is that we didn't want to change the behavior of existing compilers (many of which had pragma Assert when it was added to the language). But that probably is the wrong choice for preconditions, predicates, and so on. Randy. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-06 11:24 ` Brian Drummond 2015-12-06 18:17 ` Jeffrey R. Carter @ 2015-12-07 9:01 ` Jerry 2015-12-07 9:36 ` Jacob Sparre Andersen 2015-12-07 14:21 ` Simon Wright 1 sibling, 2 replies; 12+ messages in thread From: Jerry @ 2015-12-07 9:01 UTC (permalink / raw) On Sunday, December 6, 2015 at 4:26:49 AM UTC-7, Brian Drummond wrote: > On Sun, 06 Dec 2015 02:49:23 -0800, Jerry wrote: > > > How does one compile Barnes' examples from his book, Programming in Ada > > 2012, with GNAT? The programs are available here: cambridge.org/barnes > > -> Resources -> Programs. > > It should be as simple as "gnatmake main_program.adb". > > In fact it isn't ... quite. Taking the first on that list, XPROG6.txt for > example, I see that it has to be split into .ads files for each package, > and matching .adb files for each package body and the main program. > > Tedious ... except there's a tool called "gnatchop" to do that. > > So, > gnatchop XPROG6.txt > gnatmake tower_of_hanoi.adb > > Job done. > > -- Brian Thanks, Brian. I was kind of aware of this limitation of GNAT. This makes a mess of things. Is there a preferred way that GNAT users handle this? Do they make multiple package specs and bodies in one file then let gnatchop handle it, possibly hiding the mess in another directory, or is it preferred to write the many separate spec and body files from the start? Jerry ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-07 9:01 ` Jerry @ 2015-12-07 9:36 ` Jacob Sparre Andersen 2015-12-10 3:26 ` Jerry 2015-12-07 14:21 ` Simon Wright 1 sibling, 1 reply; 12+ messages in thread From: Jacob Sparre Andersen @ 2015-12-07 9:36 UTC (permalink / raw) Jerry <lanceboyle@qwest.net> writes: > Is there a preferred way that GNAT users handle this? Do they make > multiple package specs and bodies in one file then let gnatchop handle > it, possibly hiding the mess in another directory, or is it preferred > to write the many separate spec and body files from the start? The norm seems to be to put specifications and bodies in separate files like GNAT wants them. This seems to work with most Ada compilers, and it supports the notion that users of a package doesn't have to look at how it is implemented. Greetings, Jacob -- "Acupuncture: a jab well done." ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-07 9:36 ` Jacob Sparre Andersen @ 2015-12-10 3:26 ` Jerry 2015-12-10 8:55 ` J-P. Rosen 0 siblings, 1 reply; 12+ messages in thread From: Jerry @ 2015-12-10 3:26 UTC (permalink / raw) On Monday, December 7, 2015 at 2:36:45 AM UTC-7, Jacob Sparre Andersen wrote: > Jerry writes: > > > Is there a preferred way that GNAT users handle this? Do they make > > multiple package specs and bodies in one file then let gnatchop handle > > it, possibly hiding the mess in another directory, or is it preferred > > to write the many separate spec and body files from the start? > > The norm seems to be to put specifications and bodies in separate files > like GNAT wants them. > > This seems to work with most Ada compilers, and it supports the notion > that users of a package doesn't have to look at how it is implemented. > > Greetings, > > Jacob > -- > "Acupuncture: a jab well done." It would be nice if it were possible to put multiple specs in one file and multiple bodies in another file thus maintaining interface from implementation but without a proliferation of files. Jerry ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-10 3:26 ` Jerry @ 2015-12-10 8:55 ` J-P. Rosen 2015-12-10 12:34 ` G.B. 0 siblings, 1 reply; 12+ messages in thread From: J-P. Rosen @ 2015-12-10 8:55 UTC (permalink / raw) Le 10/12/2015 04:26, Jerry a écrit : > It would be nice if it were possible to put multiple specs in one > file and multiple bodies in another file thus maintaining interface > from implementation but without a proliferation of files. But since you submit a /file/ to the compiler, if you change something in one spec, all the specs get recompiled, possibly triggering a huge cascade of (useless) recompilations. I prefer to stick to the one-unit/one-file rule. Actually, it was already the recommended practice before Gnat made it a requirement. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-10 8:55 ` J-P. Rosen @ 2015-12-10 12:34 ` G.B. 0 siblings, 0 replies; 12+ messages in thread From: G.B. @ 2015-12-10 12:34 UTC (permalink / raw) On 10.12.15 09:55, J-P. Rosen wrote: > Le 10/12/2015 04:26, Jerry a écrit : >> It would be nice if it were possible to put multiple specs in one >> file and multiple bodies in another file thus maintaining interface >> from implementation but without a proliferation of files. > > But since you submit a /file/ to the compiler, if you change something > in one spec, all the specs get recompiled, possibly triggering a huge > cascade of (useless) recompilations. It's not necessarily true that recompilation is needed if gnatmake's -m switch does a good job: * Using `gnatmake' along with the `-m (minimal recompilation)' switch provides a mechanism for avoiding unnecessary recompilations. Using this switch, you can update the comments/format of your source files without having to recompile everything. -m seems to work reasonably well when routinely using gnatchop. If some file multi.ada has specs for procedures A and B, and I change the spec for A by adding a parameter, I see this after changing and saving multi.ada: $ gnatchop -r -w -c multi.ada && gnatmake -m b splitting multi.ada into: a.ads b.ads gnatmake: "b" up to date. With recent gnatmake/gcc, there also is a way now to have them pick one unit from a file for compilation. With gnatmake, -eI Index of unit in multi-unit source file For example, using the above file with two specs in it, $ gnatmake -gnatc -eI1 multi.ada gcc -c -gnatc -x ada -gnateI1 -o multi~1.o multi.ada $ Two subprogram specs in a file could be alike except for subtypes of parameters. So, file singlefile.ada could have two almost identical subprogram specs: $ cat singlefile.ada procedure A (X : Integer); procedure A (X : Positive); $ Using this scheme consistently, one could then see what happens when picking one or the other subprogram for compiling a program that calls A. Also, for completeness, with -gnats, "in syntax-check-only mode (..) it is possible to check a file containing multiple compilation units concatenated together". > I prefer to stick to the one-unit/one-file rule. Actually, it was > already the recommended practice before Gnat made it a requirement. With good text editors, and standard ways of handling files and directories, there shouldn't be anything affecting compilation. Surprisingly, there is. (Maybe that's the effect of Unix and MS DOS/Windows™ traditions of addressing compilation systems and files...) ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to compile Barnes' examples from his book using GNAT 2015-12-07 9:01 ` Jerry 2015-12-07 9:36 ` Jacob Sparre Andersen @ 2015-12-07 14:21 ` Simon Wright 1 sibling, 0 replies; 12+ messages in thread From: Simon Wright @ 2015-12-07 14:21 UTC (permalink / raw) Jerry <lanceboyle@qwest.net> writes: > Is there a preferred way that GNAT users handle this? Do they make > multiple package specs and bodies in one file then let gnatchop handle > it, possibly hiding the mess in another directory, or is it preferred > to write the many separate spec and body files from the start? If I'm making a brief example, or trying to build someone else's problematic code, I'd put the whole lot in a file <problem>.ada. Otherwise, specs/bodies/separates all in files of their own. ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2015-12-10 12:34 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-12-06 10:49 How to compile Barnes' examples from his book using GNAT Jerry 2015-12-06 11:24 ` Brian Drummond 2015-12-06 18:17 ` Jeffrey R. Carter 2015-12-06 21:21 ` Pascal Obry 2015-12-06 22:33 ` Jeffrey R. Carter 2015-12-08 2:01 ` Randy Brukardt 2015-12-07 9:01 ` Jerry 2015-12-07 9:36 ` Jacob Sparre Andersen 2015-12-10 3:26 ` Jerry 2015-12-10 8:55 ` J-P. Rosen 2015-12-10 12:34 ` G.B. 2015-12-07 14:21 ` Simon Wright
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox