incubator-lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marvin Humphrey <>
Subject Re: [KinoSearch] C90 vs C99
Date Thu, 14 Jan 2010 16:31:16 GMT
On Thu, Jan 14, 2010 at 09:27:48AM -0600, Peter Karman wrote:
> I seem to recall a recent move from C90 to C99 compliance (or was it the 
> reverse?) as part of a Win32 compatibility change. (I could have the details 
> wrong; memory is fuzzy.)

The new policy has never been explicity expressed.  It is basically "the
intersection of C++ and C99".  It can't quite be that because so few compilers
are 100% C99-compliant.

By compiling with MSVC in C++ mode, we are able to get the features of C99
that are most useful without dropping support for that compiler.  One of these
is "mixed declarations and code".  Another is "for loop initial declaration".


    int i, max;
    for (i = 0, max = thing->hello_count; i < max; i++) {
        printf("Greetings, earthlings!\n");


    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.

> In any case, I've seen a couple instances lately of this kind of error:
> ../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'

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"?

> I fixed one such issue in KS r5678

Heh, snuck that one by me. 

Marvin Humphrey

View raw message