On Fri, Mar 14, 2003 at 04:00:22PM +0000, Bruynooghe Floris wrote: > I can't see why the second program fails to compile, as far as I would > expect these programs are identical. The programs are not identical; prog2.c has regular code between declarations. gcc-3.2 can compile both programs, unlike 2.95. > Does anyone knows what goes wrong? seneca@tetragon:~/c$ gcc-3.2 --pedantic prog2.c prog2.c: In function `main': prog2.c:9: warning: ISO C89 forbids mixed declarations and code seneca@tetragon:~/c$ You can see that in prog1.c all the declarations occur before the code, unlike prog2.c, which has one line of code in the middle of the declarations. seneca@tetragon:~/c$ diff -u prog1.c prog2.c --- prog1.c 2003-03-14 12:20:07.000000000 -0500 +++ prog2.c 2003-03-14 12:20:35.000000000 -0500 @@ -4,10 +4,10 @@ { char* record; int record_size = 10; - int letter = 'a'; - int i; record = (char*) malloc (record_size); + int letter = 'a'; + int i; for (i=0; i < record_size; i++) { record[i] = (char) letter++; -- Seneca seneca-cunningham@rogers.com
Attachment:
pgpEHNZ8Q_wCW.pgp
Description: PGP signature