> On 26/01/2017, at 8:46 PM, Clemens Ladisch <clem...@ladisch.de> wrote: > > Ziemowit Laski wrote: >> Visual C++ > > Which one? > >> correctly catches this. > > Oh? What exactly is illegal about this? > >> struct IcuScalar { >> const char *zName; /* Function name */ >> int nArg; /* Number of arguments */ >> int enc; /* Optimal text encoding */ >> void *pContext; /* sqlite3_user_data() context >> */ >> void (*xFunc)(sqlite3_context*,int,sqlite3_value**); >> } scalars[] = { >> ... >> {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation}, >> };
The ANSI/ISO C 1990 standard states this in section 6.5.7, under Constraints: “All the expressions in an initializer for an object that has static storage duration or in an initializer list for an object that has aggregate or union type shall be constant expressions.” In this case the code is trying to initialize a field of an auto struct using the db parameter passed to the function. That is not a constant expression, and it is in an initializer list for an object that has aggregate type (whether or not the object has static storage duration), so is disallowed under ANSI/ISO C 1990. Later versions of the C standard removed the bit about aggregate or union types, leaving only the static restriction, e.g. from section 6.7.8 of the draft C99 standard: "All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals.” Visual C++ is based on C90, and assuming Wikipedia has the details right, it wasn’t until Visual C++ 2013 that Microsoft started making changes to support C99. Should SQLite be aiming for the 1990 version of ANSI/ISO C as a baseline, for widest compatibility, or is it OK to drop older compilers and require C99 compliance? The only obvious reference I found in the SQLite documentation was http://www.sqlite.org/howtocompile.html which mentions “ANSI-C”. That is generally understood to mean the ANSI C 1989 standard, which was adopted internationally as ISO 9899:1990. -- David Empson demp...@emptech.co.nz _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users