From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c840deaa6965e67a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-01-26 12:20:58 PST Path: pad-thai.cam.ov.com!bloom-beacon.mit.edu!news.kei.com!news.mathworks.com!hookup!swrinde!howland.reston.ans.net!news.sprintlink.net!pipex!uknet!hrc63!gmrc.gecm.com!valiant!bill From: bill@valiant (R.A.L Williams) Newsgroups: comp.lang.ada Subject: Memory overwrite? Date: 26 Jan 1995 13:05:58 GMT Organization: GEC-Marconi Research Centre Message-ID: <3g86nm$mj3@miranda.gmrc.gecm.com> NNTP-Posting-Host: valiant.gmrc.gecm.com X-Newsreader: TIN [version 1.2 PL1] Date: 1995-01-26T13:05:58+00:00 List-Id: 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! :  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 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