[KinoSearch] C90 vs C99
Peter Karman
peter at peknet.com
Thu Jan 14 08:39:20 PST 2010
Marvin Humphrey wrote on 1/14/10 10:31 AM:
> Before:
>
> int i, max;
> for (i = 0, max = thing->hello_count; i < max; i++) {
> printf("Greetings, earthlings!\n");
> }
>
> After:
>
> for (int i = 0, max = thing->hello_count; i < max; i++) {
> printf("Greetings, earthlings!\n");
> }
>
> The latter is better because it scope-limits "i" and "max" to the loop where
> they are needed.
>
yes, I can see why it's better. As long as it compiles, that is. ;)
> A web search reveals that this is a GCC error, but it's unexpected because GCC
> should be tolerant by default. Do the flags that you're passing to GCC
> include "-std=c90", "-std=C89", or "-ansi"?
>
>
no.
cc -I. -I../core -Iautogen -Ixs -I../charmonizer/gen
-I/opt/pij/lib/perl5/5.8.9/x86_64-linux/CORE -fPIC -c -fno-strict-aliasing -pipe
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/usr/include/gdbm -O2 -o ../core/KinoSearch/Util/SortExternal.o
../core/KinoSearch/Util/SortExternal.c
../core/KinoSearch/Util/SortExternal.c: In function `S_find_endpost':
../core/KinoSearch/Util/SortExternal.c:194: error: 'for' loop initial
declaration used outside C99 mode
error building ../core/KinoSearch/Util/SortExternal.o from
'../core/KinoSearch/Util/SortExternal.c' at
/opt/pij/lib/perl5/site_perl/5.8.9/ExtUtils/CBuilder/Base.pm line 112.
make: *** [test] Error 2
[pijuser at pijnatdev perl]$ cc -v
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)
--
Peter Karman . http://peknet.com/ . peter at peknet.com
More information about the kinosearch
mailing list