comp.lang.ada
 help / color / mirror / Atom feed
From: bill@valiant (R.A.L Williams)
Subject: Memory overwrite?
Date: 26 Jan 1995 13:05:58 GMT
Date: 1995-01-26T13:05:58+00:00	[thread overview]
Message-ID: <3g86nm$mj3@miranda.gmrc.gecm.com> (raw)

In article <3g6fi6$fuv@gnat.cs.nyu.edu> Robert Dewar wrote:
: Mark asks if GNAT can also find uninitialized variables, like GCC.

No, actually it was me

: GNAT IS GCC! Use the GCC option, and you will get the output you want!
: \x1a

Well, no! I used these two programs...

with GNAT.IO; 
use GNAT.IO;

procedure CRASH is
  subtype CONSTRAINED_INT is INTEGER range 2 .. 5;
  I : INTEGER;
  J : CONSTRAINED_INT;
  X : array(CONSTRAINED_INT) of INTEGER;
begin
  for I in CONSTRAINED_INT'RANGE loop
    X(I) := I * 2;
    PUT(I); PUT(" : "); PUT(X(I)); NEW_LINE;
  end loop;
  PUT_LINE("The next command may cause a CONSTRAINT_ERROR");
  PUT(J); PUT(" : "); PUT(X(J)); NEW_LINE;
end;

compiled with 'gnat -c -O -Wuninitialized crash.adb' gave no
errors and no warnings; whereas

#include <stdio.h>

main()
{
  int i, j, x[4];

  for (i = 0; i < sizeof(x)/sizeof(int); i++)
  {
    x[i] = (i + 2) * 2;
    printf("%d : %d\n", i, x[i]);
  }
  printf("The next statement may cause a crash\n");
  printf("%d : %d\n", j, x[j]);
}

compiled with 'gcc -O -Wuninitialized -o crash-c crash-c.c'
told me:
  crash-c.c: In function `main':
  crash-c.c:5: warning: `j' might be used uninitialized in this function

Obviously this is a compiler issue, NOT a language issue. There is
no reason that I know of why future versions of GNAT shouldn't generate
similar warnings in these circumstances.

Interestingly, the -Wuninitialized option only works when optimization
is enabled. Does this imply that there isn't much optimization in
GNAT yet. (Can't complain, it is free and available and you cant say that
about any other Ada95 compilers).

Bill Williams




             reply	other threads:[~1995-01-26 13:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-01-26 13:05 R.A.L Williams [this message]
1995-01-27 14:01 ` Memory overwrite? Robert A Duff
1995-01-28 22:49   ` Robert Dewar
1995-01-30 14:16     ` Robert A Duff
1995-02-01 23:00       ` Matt Kennel
1995-01-28  5:54 ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1995-01-24 12:47 R.A.L Williams
1995-01-25 16:31 ` Robert A Duff
1995-01-25 19:01 ` Tucker Taft
1995-01-25 21:24 ` Robert Dewar
1995-01-30 17:06 ` Theodore E. Dennison
1995-02-01 12:25   ` Robert Dewar
1995-01-13  8:35 Rick Wouters
     [not found] ` <3fe5cp$fnq@theopolis.orl.mmc.com>
1995-01-18 18:20   ` Mark A Biggar
1995-01-20  5:19     ` Robert Dewar
replies disabled

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