comp.lang.ada
 help / color / mirror / Atom feed
* What does -gnato do?
@ 2006-08-26 22:52 Peter C. Chapin
  2006-08-27  1:51 ` Jeffrey R. Carter
  2006-08-27  8:55 ` Martin Krischik
  0 siblings, 2 replies; 7+ messages in thread
From: Peter C. Chapin @ 2006-08-26 22:52 UTC (permalink / raw)


I'm using GNAT GPL 2006. In the User's Guide there is a description of 
the -gnato option. This description includes the following example:

---> begin quote <---
X1 : Integer := Integer'Last;
X2 : Integer range 1 .. 5 := 5;
...
X1 := X1 + 1;
X2 := X2 + 1;

Here the first addition results in a value that is outside the base 
range of Integer, and hence requires an overflow check for detection of 
the constraint error. Thus the first assignment to X1 raises a 
Constraint_Error exception only if `-gnato' is set. 
---> end quote <---

Now consider the following program:

---> begin program <---
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Check is
   X : Integer := Integer'Last;
begin
   X := X + 1;
   Put(X);
end Check;
---> end program <---

When I build this program *without* the -gnato option I get the 
following warning:

C:\home\Languages\Ada>gnatmake check.adb
gcc -c check.adb
check.adb:6:11: warning: value not in range of type "Standard.Integer"
check.adb:6:11: warning: "Constraint_Error" will be raised at run time
gnatbind -x check.ali
gnatlink check.ali

And when I run the result I get

C:\home\Languages\Ada>check

raised CONSTRAINT_ERROR : check.adb:6 overflow check failed


So it seems that overflow checking is enabled even without -gnato 
despite the fact that this contradicts the documentation. I conclude 
that the default has changed and the documentation is out of date. Is 
that true or am I misunderstanding something?

Note that when I include the -gnato option in the compilation of my 
sample program the effect is the same. The -gnato option doesn't change 
anything in this case.

Peter



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

* Re: What does -gnato do?
  2006-08-26 22:52 What does -gnato do? Peter C. Chapin
@ 2006-08-27  1:51 ` Jeffrey R. Carter
  2006-08-27  8:55 ` Martin Krischik
  1 sibling, 0 replies; 7+ messages in thread
From: Jeffrey R. Carter @ 2006-08-27  1:51 UTC (permalink / raw)


Peter C. Chapin wrote:
> 
> with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
> procedure Check is
>    X : Integer := Integer'Last;
> begin
>    X := X + 1;
>    Put(X);
> end Check;
> 
> When I build this program *without* the -gnato option I get the 
> following warning:
> 
> check.adb:6:11: warning: value not in range of type "Standard.Integer"
> check.adb:6:11: warning: "Constraint_Error" will be raised at run time

It's apparent that the compiler has calculated the result of the 
addition in order to issue this warning. It may then have replaced the 
assignment by "raise Constraint_Error;".

Make the value of X dynamic and see if -gnato makes a difference:

X : Integer := Integer'Value (Ada.Command_Line.Argument (1) );

-- 
Jeff Carter
"Sheriff murdered, crops burned, stores looted,
people stampeded, and cattle raped."
Blazing Saddles
35



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

* Re: What does -gnato do?
  2006-08-26 22:52 What does -gnato do? Peter C. Chapin
  2006-08-27  1:51 ` Jeffrey R. Carter
@ 2006-08-27  8:55 ` Martin Krischik
  2006-08-27 11:12   ` Peter C. Chapin
  1 sibling, 1 reply; 7+ messages in thread
From: Martin Krischik @ 2006-08-27  8:55 UTC (permalink / raw)


Peter C. Chapin wrote:

> C:\home\Languages\Ada>gnatmake check.adb
> gcc -c check.adb
> check.adb:6:11: warning: value not in range of type "Standard.Integer"
> check.adb:6:11: warning: "Constraint_Error" will be raised at run time
> gnatbind -x check.ali
> gnatlink check.ali

-gnato enables runtime checks but the warning results from a compile time
check. The ability to make quite a lot of checks at compile time - rather
then runtime - is a is one great advantage of the Ada Syntax and Sematic:

Compile time check do not reduce performace of the final application :-)
they might however increase performance :-)) and thefore there is really no
need to disable them.

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



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

* Re: What does -gnato do?
  2006-08-27  8:55 ` Martin Krischik
@ 2006-08-27 11:12   ` Peter C. Chapin
  2006-08-28 11:49     ` Stephen Leake
  0 siblings, 1 reply; 7+ messages in thread
From: Peter C. Chapin @ 2006-08-27 11:12 UTC (permalink / raw)


Martin Krischik <krischik@users.sourceforge.net> wrote in
news:1636357.gWrtX1Nq9K@linux1.krischik.com: 

> -gnato enables runtime checks but the warning results from a compile
> time check. The ability to make quite a lot of checks at compile time
> - rather then runtime - is a is one great advantage of the Ada Syntax
> and Sematic: 

You are right in that if I do the overflow with values that can only be 
known at run time, the -gnato makes a difference. Without the option, 
the results wrap around but with the option I get Constraint_Error.

So it seems that without -gnato the externally visible behavior of a 
program depends on the extent with which the compiler can analyze the 
code. If the compiler's analysis is sufficiently deep I might end up 
with a Constraint_Error that I wouldn't get if the analysis was not as 
deep. I'm not sure how I feel about that. It seems like a bad idea to me 
although I can't articulate exactly why I feel that way.

Peter



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

* Re: What does -gnato do?
  2006-08-27 11:12   ` Peter C. Chapin
@ 2006-08-28 11:49     ` Stephen Leake
  2006-08-28 21:35       ` Jeffrey R. Carter
  2006-09-05 23:37       ` Randy Brukardt
  0 siblings, 2 replies; 7+ messages in thread
From: Stephen Leake @ 2006-08-28 11:49 UTC (permalink / raw)


"Peter C. Chapin" <pchapin@sover.net> writes:

> Martin Krischik <krischik@users.sourceforge.net> wrote in
> news:1636357.gWrtX1Nq9K@linux1.krischik.com: 
>
> You are right in that if I do the overflow with values that can only be 
> known at run time, the -gnato makes a difference. Without the option, 
> the results wrap around but with the option I get Constraint_Error.
>
> So it seems that without -gnato the externally visible behavior of a 
> program depends on the extent with which the compiler can analyze the 
> code. If the compiler's analysis is sufficiently deep I might end up 
> with a Constraint_Error that I wouldn't get if the analysis was not as 
> deep. I'm not sure how I feel about that. It seems like a bad idea to me 
> although I can't articulate exactly why I feel that way.

You are right to feel dismayed by such behavior; it means the program
is not portable among compilers, or even compiler versions. 

Which is why standard Ada does not allow such behavior. GNAT without
-gnato is _not_ a standard Ada compiler!

In defense of GNAT, specifying -gnato does add size to the code, and
it runs somewhat slower. Back when GNAT was first introduced, there
were lots of rumors about how slow and bloated Ada is. So AdaCore made
the decision to opt for speed and small size by default, rather than
complete Ada correctness. A lot of us complained about that, but it's
too late to complain about it now.

-- 
-- Stephe



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

* Re: What does -gnato do?
  2006-08-28 11:49     ` Stephen Leake
@ 2006-08-28 21:35       ` Jeffrey R. Carter
  2006-09-05 23:37       ` Randy Brukardt
  1 sibling, 0 replies; 7+ messages in thread
From: Jeffrey R. Carter @ 2006-08-28 21:35 UTC (permalink / raw)


Stephen Leake wrote:
> 
> Which is why standard Ada does not allow such behavior. GNAT without
> -gnato is _not_ a standard Ada compiler!

I think you also need -f stack-check. Technically, -gnatE may be 
required, but if GNAT will link your program without it, it doesn't 
really matter.

> In defense of GNAT, specifying -gnato does add size to the code, and
> it runs somewhat slower. Back when GNAT was first introduced, there
> were lots of rumors about how slow and bloated Ada is. So AdaCore made
> the decision to opt for speed and small size by default, rather than
> complete Ada correctness. A lot of us complained about that, but it's
> too late to complain about it now.

IIRC, at the time, on at least one popular processor, overflow checks 
were very slow. That led to the decision. The checks are no longer 
exceptionally expensive, but the default remains the same.

-- 
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail
18



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

* Re: What does -gnato do?
  2006-08-28 11:49     ` Stephen Leake
  2006-08-28 21:35       ` Jeffrey R. Carter
@ 2006-09-05 23:37       ` Randy Brukardt
  1 sibling, 0 replies; 7+ messages in thread
From: Randy Brukardt @ 2006-09-05 23:37 UTC (permalink / raw)


"Stephen Leake" <stephen_leake@stephe-leake.org> wrote in message
news:uhczxyt9o.fsf@stephe-leake.org...
> ...A lot of us complained about that, but it's
> too late to complain about it now.

<Nit-pick on>
It's never too late to complain. I expect I'll be complaining about the 2000
election until I die. :-) And probably -gnato, too. It's rare that anything
useful happens from complaining, anyway -- useful stuff comes from
"comments" or "feedback", not complaining.

It *is* too late for anything useful to happen for either example, though,
so discussion surely is complaining.
<Nit-pick off>

                 Randy.





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

end of thread, other threads:[~2006-09-05 23:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-26 22:52 What does -gnato do? Peter C. Chapin
2006-08-27  1:51 ` Jeffrey R. Carter
2006-08-27  8:55 ` Martin Krischik
2006-08-27 11:12   ` Peter C. Chapin
2006-08-28 11:49     ` Stephen Leake
2006-08-28 21:35       ` Jeffrey R. Carter
2006-09-05 23:37       ` Randy Brukardt

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