SQLite Forum

Tiny C99-ism in sqlite3.c breaks C89 build compatibility
Login

Tiny C99-ism in sqlite3.c breaks C89 build compatibility

(1) By Stephan Beal (stephan) on 2021-02-07 10:23:36 [link] [source]

From a client tree which has always used -std=c89 to build with:

sqlite3.c: In function ‘sqlite3ExpandReturning’:
sqlite3.c:138692:9: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
138692 |         Expr *pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zName);
       |         ^~~~
cc1: all warnings being treated as errors

The relevant bit of sqlite3.c:

$ sed -n 138689,138695p sqlite3.c
      int jj;
      for(jj=0; jj<pTab->nCol; jj++){
        if( IsHiddenColumn(pTab->aCol+jj) ) continue;
        Expr *pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zName);
        pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
        if( !db->mallocFailed ){
          struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];

$ fossil status
...
checkout:     b469327e2949352325d3db815bd4782f9734239c 2021-02-06 14:56:30 UTC

(2) By Wout Mertens (wmertens) on 2021-02-07 11:43:34 in reply to 1 [link] [source]

I have to wonder why you don't compile with c99? It's been more than 30 years since c89...

(3) By Stephan Beal (stephan) on 2021-02-07 11:52:14 in reply to 2 [link] [source]

It's been more than 30 years since c89...

That is a topic long-since beaten to death, so i won't drag it out, but two significant points:

a) MSVC didn't fully support C99 until something like 2015, and these forums often have users who are using much older tools than that.

b) Richard reportedly still has at least one old platform he builds sqlite3 on which needs C89 compatibility.

(4) By MBS on 2021-02-07 12:39:38 in reply to 1 [source]

Thanks for reporting. This should be a quick change for Richard.

(5) By Larry Brasfield (larrybr) on 2021-02-07 19:11:34 in reply to 4 [link] [source]

He committed the fix 20 minutes after your prognosis, very minimally as you can see.