comp.lang.ada
 help / color / mirror / Atom feed
From: James Rogers <jimmaureenrogers@att.net>
Subject: Re: Case sensitivity (was Re: no title)
Date: Fri, 06 Jun 2003 01:24:09 GMT
Date: 2003-06-06T01:24:09+00:00	[thread overview]
Message-ID: <Xns9391C4BCD5A8Bjimmaureenrogers@204.127.36.1> (raw)
In-Reply-To: ullwgh20s.fsf@nasa.gov

Stephen Leake <Stephe.Leake@nasa.gov> wrote in news:ullwgh20s.fsf@nasa.gov:

> Hyman Rosen <hyrosen@mail.com> writes:
> 
>> If I'm not mistaken, the following code *does* compile.
>> 
>>      for index in my_array'range loop
>>          declare
>>              Index : integer := 27;
>>          begin
>>              if my_array ( Index ) > current_maximum
>>              then
>>                  current_maximum := my_array ( index );
>>                  Index := index;
>>              end if;
>>          end;
>>      end loop;
> 
> Yes, it does, and it has a bug. If the language was not
> case-sensitive, the bug would be easier to see.
> 

When I place this snippet into a real program I do get a clean
compile. The program does generate an exception at run time on
the first loop iteration.

with Ada.Text_Io;
use Ada.Text_Io;
procedure Badloop is 
   type Foo_Array is array (1 .. 10) of Integer; 
   My_Array        : Foo_Array := (10, 9, 8, 7, 6, 5, 4, 3, 2, 1);  
   Current_Maximum : Integer   := 1;  
begin
   for Index in My_Array'range loop
      declare
         Index : Integer := 27;  
      begin
         if My_Array ( Index ) > Current_Maximum
               then
            Current_Maximum := My_Array ( Index );
            Index := Index;
         end if;
      end;
   end loop;
   Put_Line("Current_Maximum:" & Integer'Image(Current_Maximum));
end Badloop;
    
Note that the above bad code is not solved by making your
language case sensitive.

A C example:

for(i = 0; i < 9; ++i) {
   int i = 27;
   if (My_Array[i] > currentMaximum) {
      currentMaximum = My_Array[i];
      i = i;
   }
{

The C compiler will compile this program without error.
The difference is that the C compiler will allow you to
access beyond the end of the array with no complaints.
In fact, this program will run for an at least one full
iteration, and possibly more. 

Ada still ends up being safer than C because it prevents
array bounds violations at run-time.

Jim Rogers



  parent reply	other threads:[~2003-06-06  1:24 UTC|newest]

Thread overview: 190+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-02  7:55 no title And838N
2003-06-02  8:09 ` Preben Randhol
2003-06-02 10:41   ` Case sensitivity (was Re: no title) Sergey Koshcheyev
2003-06-02 11:03     ` Bobby D. Bryant
2003-06-02 11:12     ` Preben Randhol
2003-06-02 11:56       ` Sergey Koshcheyev
2003-06-02 12:46         ` Bobby D. Bryant
2003-06-02 13:50           ` Sergey Koshcheyev
2003-06-02 14:35             ` Preben Randhol
2003-06-02 14:51               ` Sergey Koshcheyev
2003-06-02 14:52               ` Bill Findlay
2003-06-02 20:36               ` Alexander Kopilovitch
2003-06-02 12:55         ` Preben Randhol
2003-06-02 12:58           ` Preben Randhol
2003-06-02 13:54             ` Sergey Koshcheyev
2003-06-02 14:44               ` Preben Randhol
2003-06-02 15:06                 ` Sergey Koshcheyev
2003-06-02 15:42                   ` Preben Randhol
2003-06-03  1:15                 ` Randy Brukardt
2003-06-03  3:47                   ` John R. Strohm
2003-06-03 11:36                     ` Preben Randhol
2003-06-03 15:05                       ` Robert I. Eachus
2003-06-03 20:12                         ` Randy Brukardt
2003-06-05  1:48                           ` Robert I. Eachus
2003-06-03 16:25                       ` David C. Hoos
2003-06-02 13:24     ` Arthur Evans Jr
2003-06-02 13:38       ` Sergey Koshcheyev
2003-06-02 15:20         ` Robert C. Leif
2003-06-02 15:33           ` Larry Kilgallen
2003-06-03  1:35             ` Randy Brukardt
2003-06-05 17:30           ` Larry Hazel
2003-06-05 17:55           ` Hyman Rosen
2003-06-08  1:52       ` AG
2003-06-08  3:24         ` Hyman Rosen
2003-06-08  4:36           ` AG
2003-06-08  4:39             ` Hyman Rosen
2003-06-02 15:48     ` Martin Dowie
2003-06-02 18:18     ` Mike Silva
2003-06-02 18:29       ` Hyman Rosen
2003-06-02 18:40         ` tmoran
2003-06-02 18:51           ` Bobby D. Bryant
2003-06-02 21:24             ` Mike Silva
2003-06-03  3:50             ` John R. Strohm
2003-06-03  9:29             ` Georg Bauhaus
2003-06-02 19:02           ` Hyman Rosen
2003-06-02 20:28             ` tmoran
2003-06-03  9:33             ` Georg Bauhaus
2003-06-02 19:06           ` Georg Bauhaus
2003-06-03  3:49           ` John R. Strohm
2003-06-03  7:42           ` Jean-Pierre Rosen
2003-06-02 21:21         ` Mike Silva
2003-06-02 21:56           ` Hyman Rosen
2003-06-02 22:56             ` Larry Kilgallen
2003-06-02 23:30             ` Preben Randhol
2003-06-08  2:26             ` AG
2003-06-03  7:41       ` Jean-Pierre Rosen
2003-06-03 14:06         ` Hyman Rosen
2003-06-03 14:31           ` Preben Randhol
2003-06-03 14:49             ` Hyman Rosen
2003-06-03 16:29           ` Jean-Pierre Rosen
2003-06-03 18:06             ` Hyman Rosen
2003-06-03 18:34           ` Mike Silva
2003-06-03 18:53             ` Hyman Rosen
2003-06-04 10:41               ` Preben Randhol
2003-06-04 14:11                 ` Hyman Rosen
2003-06-04 15:48                   ` Preben Randhol
2003-06-04 16:03                     ` Hyman Rosen
2003-06-04 16:24                       ` Preben Randhol
2003-06-04 17:30                         ` Hyman Rosen
2003-06-04 17:36                           ` Preben Randhol
2003-06-04 17:52                             ` Hyman Rosen
2003-06-04 17:05                     ` Larry Kilgallen
2003-06-04 17:45                       ` Hyman Rosen
2003-06-05 17:23                         ` Stephen Leake
2003-06-05 17:51                           ` Hyman Rosen
2003-06-06  1:24                           ` James Rogers [this message]
2003-06-06  9:01                             ` Simon Wright
2003-06-06 10:35                               ` Preben Randhol
2003-06-05 17:51                     ` Larry Kilgallen
2003-06-08  5:28                       ` AG
2003-06-04 16:19                   ` Larry Kilgallen
2003-06-04 21:45                     ` Mike Silva
2003-06-08  3:56                   ` AG
2003-06-08  4:14                     ` Hyman Rosen
2003-06-08  4:46                       ` AG
2003-06-08  4:59                         ` Hyman Rosen
2003-06-08  5:11                           ` AG
2003-06-08  5:14                             ` Hyman Rosen
2003-06-08 10:09                       ` Frank J. Lhota
2003-06-09  3:06                         ` Wesley Groleau
2003-06-09  3:48                         ` Hyman Rosen
2003-06-09 21:09                         ` Warren W. Gay VE3WWG
2003-06-10  3:36                           ` Wesley Groleau
2003-06-10 16:02                             ` Warren W. Gay VE3WWG
2003-06-09 16:56                       ` Warren W. Gay VE3WWG
2003-06-09 18:21                         ` Hyman Rosen
2003-06-09 21:06                           ` Warren W. Gay VE3WWG
2003-06-10 10:23                           ` Preben Randhol
2003-06-12 21:58                             ` Michael Bode
2003-06-03  2:44     ` Steve
2003-06-03  3:13       ` Wesley Groleau
2003-06-03  3:41         ` Hyman Rosen
2003-06-03 11:41           ` Preben Randhol
2003-06-03 13:30             ` Hyman Rosen
2003-06-03 13:46               ` Vinzent Hoefler
2003-06-03 14:30                 ` Preben Randhol
2003-06-03 15:16                   ` Vinzent Hoefler
2003-06-03 15:36                     ` Preben Randhol
2003-06-03 14:28               ` Preben Randhol
2003-06-03 14:37                 ` Hyman Rosen
2003-06-03 14:51                   ` Preben Randhol
2003-06-03 15:03                     ` Hyman Rosen
2003-06-03 18:12                       ` Wesley Groleau
2003-06-08  5:46                       ` AG
2003-06-08  6:30                         ` Hyman Rosen
2003-06-08  8:24                           ` AG
2003-06-08  9:43                             ` Hyman Rosen
2003-06-09  3:03                               ` Wesley Groleau
2003-06-03 15:05                   ` John R. Strohm
2003-06-03 15:31                     ` Hyman Rosen
2003-06-04 10:16                       ` Ole-Hjalmar Kristensen
2003-06-03 17:21                   ` Robert A Duff
2003-06-03 17:40                     ` Preben Randhol
2003-06-03 18:20                     ` Wesley Groleau
2003-06-03 19:16                     ` Sergey Koshcheyev
2003-06-03 19:44                       ` Robert A Duff
2003-06-04  2:05                   ` James Rogers
2003-06-04  2:40                     ` Wesley Groleau
2003-06-04 11:14                       ` Preben Randhol
2003-06-04  6:21                     ` Hyman Rosen
2003-06-04 13:46                       ` Jim Rogers
2003-06-04 14:22                         ` Hyman Rosen
2003-06-04 19:26                           ` Jim Rogers
2003-06-04 20:00                             ` Hyman Rosen
2003-06-04 20:24                               ` David C. Hoos
2003-06-04 20:40                                 ` Hyman Rosen
2003-06-04 22:11                               ` Wesley Groleau
2003-06-04 21:13                             ` Simon Wright
2003-06-05 17:27                               ` Stephen Leake
2003-06-04 13:54                       ` Leif Roar Moldskred
2003-06-08  6:08                       ` AG
2003-06-08  6:25                         ` Hyman Rosen
2003-06-08  8:20                           ` AG
2003-06-08  9:48                             ` Hyman Rosen
2003-06-10  8:23                               ` Leif Roar Moldskred
2003-06-10 14:11                                 ` Hyman Rosen
2003-06-10 14:58                                   ` Leif Roar Moldskred
2003-06-10 16:05                                     ` Hyman Rosen
2003-06-10 16:37                                       ` Preben Randhol
2003-06-10 17:16                                         ` Hyman Rosen
2003-06-10 17:28                                           ` Preben Randhol
2003-06-10 18:14                                             ` Hyman Rosen
     [not found]                     ` <0egDa.45 <1055265377.116836@master.nyc.kbcfp.com>
2003-06-10 18:19                       ` Matthew Woodcraft
2003-06-10 20:36                         ` Hyman Rosen
2003-06-10 23:04                           ` Matthew Woodcraft
2003-06-04 12:07                   ` Larry Kilgallen
2003-06-08  4:22               ` AG
2003-06-08  4:41                 ` Hyman Rosen
2003-06-08  4:58                   ` AG
2003-06-08  5:00                     ` Hyman Rosen
2003-06-03  8:38         ` Vinzent Hoefler
2003-06-03 18:26           ` Wesley Groleau
2003-06-03  9:53       ` Martin Dowie
2003-06-03 11:37       ` Larry Kilgallen
2003-06-08  1:21     ` AG
2003-06-08  3:21       ` Hyman Rosen
2003-06-02 10:56 ` no title Georg Bauhaus
2003-06-02 11:01 ` Bobby D. Bryant
2003-06-02 20:23 ` Gautier Write-only
2003-06-02 21:33 ` Luke A. Guest
  -- strict thread matches above, loose matches on Subject: below --
2003-06-04 16:30 Case sensitivity (was Re: no title) Lionel.DRAGHI
2003-06-04 17:57 ` Hyman Rosen
2003-06-05  9:07 Lionel.DRAGHI
2003-06-05 14:13 ` Hyman Rosen
2003-06-05 15:39   ` Preben Randhol
2003-06-05 15:44   ` Larry Kilgallen
2003-06-05 15:49     ` Preben Randhol
2003-06-05 16:28       ` Sergey Koshcheyev
2003-06-05 17:14         ` Preben Randhol
2003-06-05 16:36     ` Hyman Rosen
2003-06-05 16:53       ` Larry Kilgallen
2003-06-05 17:15         ` Preben Randhol
2003-06-05 17:30 ` Wesley Groleau
2003-06-05  9:21 Lionel.DRAGHI
2003-06-05 14:14 ` Hyman Rosen
2003-06-05 17:34   ` Stephen Leake
2003-06-05 17:31 ` Stephen Leake
2003-06-05 19:31   ` Wesley Groleau
2003-06-10 11:14 Lionel.DRAGHI
2003-06-11 10:48 Lionel.DRAGHI
replies disabled

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