Skip to content

Convert K&R function definitions to ANSI C; fix GCC 16 / C23 build#526

Open
gonsolo wants to merge 26 commits into
RTimothyEdwards:masterfrom
gonsolo:modernize-knr-to-ansi-c
Open

Convert K&R function definitions to ANSI C; fix GCC 16 / C23 build#526
gonsolo wants to merge 26 commits into
RTimothyEdwards:masterfrom
gonsolo:modernize-knr-to-ansi-c

Conversation

@gonsolo

@gonsolo gonsolo commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Converts the old-style (K&R) function definitions across the tree to ANSI C
prototypes, formatted in the project's convention — the return type on its own
line, and each parameter on its own line indented four spaces with its original
comment retained — and adds the -std=gnu17 flag needed for the GCC 16 / C23
build.

The change is organized as one commit per directory on top of a single
build commit, in dependency order (low-level first). Each directory commit
bundles its own header changes together with its definitions, so it is
self-consistent and every prefix of the series builds; it can be reviewed and
merged a directory at a time.

  • All ~1162 K&R definitions converted (complete).
  • Explicit prototypes / forward typedefs added where the now-stricter prototypes
    require them (FontChar, TileType, the netlist types); generic callbacks
    (e.g. TechAddClient) kept unprototyped; callback casts added where typed
    functions are stored in generic (*)() slots.
  • One latent bug fixed: dbStampFunc was defined with two parameters but called
    recursively with one (hidden by the old K&R declaration).

Verified with a clean-from-scratch GCC 16 build: 0 errors, only the same benign
-Wdiscarded-qualifiers warnings as before; tclmagic.so links.

@gonsolo gonsolo mentioned this pull request Jun 9, 2026
@dlmiles

dlmiles commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

AI generated, yes this could have been done this way a while ago using such a method.

Please take a look at the commit history for similar work done to the standard we are looking for.

This does not follow a number of already established source conventions in the project.

FWIW I do have the over 10 subdirs already converted, as we are finding out with AI, the time sink is in QA and testing (not creating/modifying code) and the only reason it has not been released sooner is that it hasn't passed my own standards for QA for release.

Maybe specific compiler (GCC16) concerns can be fixed with CFLAGS="-std=c17 -g -D_DEFAULT_SOURCE=1" ./configure

@gonsolo gonsolo force-pushed the modernize-knr-to-ansi-c branch from d32aa41 to fce7b5c Compare June 9, 2026 23:28
@gonsolo

gonsolo commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Please take a look at the commit history for similar work done to the standard we are looking for.

This uses c17 to keep the changes small (ahem). Later standards can be done subsequently.

This does not follow a number of already established source conventions in the project.

Ok.

FWIW I do have the over 10 subdirs already converted, as we are finding out with AI, the time sink is in QA and testing (not creating/modifying code) and the only reason it has not been released sooner is that it hasn't passed my own standards for QA for release.

I told Claude to write a smoke test (it's in the commit message). I was looking for a testsuite but didn't find one, that's the real QA in my opinion. Claude could be told to emit one for every line he changed and test it before and after the conversion. That and two or more humans looking over the code and testsuite would be a real improvement.

@RTimothyEdwards

Copy link
Copy Markdown
Owner

@gonsolo : As far as "established source conventions", please look at, for example, something like cif/CIFwrite.c line 118. The question is not one of syntax but of style:

bool
CIFWrite(
    CellDef *rootDef,     /* Pointer to CellDef to be written */
    FILE *f)                       /* Open output file */
{
    ....

Each argument is on a separate line, indented four spaces. An explanation of each argument (if available) follows on the same line. The return value type is on a separate line above the routine name. Arguments which are unused are so stated in the comment.

If the style is followed, then I am okay with reviewing and approving fixes in batches of up to a few hundred at a time. Darryl has been feeding me fixes one directory at a time, which I think is a good practice.

gonsolo and others added 25 commits June 10, 2026 03:48
GCC 16 defaults to C23, where "()" in a function declaration means
"(void)" rather than "unspecified arguments".  That breaks the many
legacy K&R-style "()" declarations still present throughout the tree,
independently of the K&R-to-ANSI conversion that follows in subsequent
per-directory commits.

Add -std=gnu17 (single dash; clang silently ignores the "--std=" long
form some CI scripts pass) in the gcc SHLIB_CFLAGS block and the
emscripten target to restore C17 semantics, and drop the now-unnecessary
-Wno-implicit-int suppression from the emscripten target.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in utils/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates the utils headers (netlist.h, stack.h, undo.h, macros.h) to
prototype the affected declarations.  TechAddClient keeps a generic
(unprototyped) declaration because its per-section callbacks have
intentionally varying signatures; its "opt" parameter is typed int (not
bool) so the empty-parameter-list declaration stays compatible with the
prototyped definition under C23.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in database/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates the database prototypes through the database.h.in template
(database.h is generated) and adds a forward typedef for FontChar so
those prototypes need not pull in database/fonts.h.  Also fixes a latent
bug exposed by the now-checked prototype: dbStampFunc was defined with two
parameters but called recursively with one.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in graphics/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Adds a forward typedef for TileType in graphics.h so the GrClipTriangle
prototype can name it without creating a circular include with the
database layer.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in dbwind/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates dbwind.h, including a prototype for the combined DBWloadWindow
declaration.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in textio/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in tcltk/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in drc/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates drc.h with prototypes for the affected declarations.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in extflat/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates the extflat headers (extflat.h, EFint.h) to prototype the
affected declarations.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in extract/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates the extract headers (extract.h, extractInt.h).  Where the
generically-typed node-name callback field is assigned the now-prototyped
extArrayTileToNode / extSubtreeTileToNode, the assignment is cast to the
field's function-pointer type.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in select/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates select.h with prototypes for the affected declarations.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in gcr/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates gcr.h with prototypes for the affected declarations.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in router/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates the router headers (router.h, routerInt.h) and adds forward
typedefs for the netlist types (NLTermLoc, NLTerm, NLNet) named by the new
prototypes.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in grouter/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates grouter.h with prototypes for the affected declarations.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in mzrouter/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in garouter/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates garouter.h.  Callbacks passed to generic function-pointer
parameters (RtrStemProcessAll, the split-paint-plane hook) are cast to the
expected pointer type at the call sites.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in irouter/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates irInternal.h with prototypes for the affected declarations.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in lisp/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in plow/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in plot/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in resis/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in netmenu/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in debug/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Corrects the HistCreate / HistAdd declarations in debug.h to use bool
for the ptrKeys parameter, matching their definitions.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in windows/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Updates the windows headers (windows.h, windInt.h) to prototype the
affected declarations.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in commands/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Convert the old-style (K&R) function definitions in oa/ to ANSI C
prototypes, formatted in the project's convention: the return type on its
own line and each parameter on its own line, indented four spaces, with
the original parameter comments retained.

Builds cleanly under GCC 16 / C23 (with the -std=gnu17 build change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gonsolo gonsolo force-pushed the modernize-knr-to-ansi-c branch from fce7b5c to 435daea Compare June 10, 2026 02:03
@gonsolo

gonsolo commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@RTimothyEdwards thanks for the style guidance — I've reworked the PR to follow it.

  • Style: every converted definition now matches the convention from cif/CIFwrite.c — return type on its own line, each argument on its own line indented four spaces, with the original per-argument comments retained. Function-pointer and multi-argument parameters are handled.
  • Split per directory: it's now one commit per directory (utils, database, graphics, … windows, commands, oa), preceded by a single build commit for the -std=gnu17 flag. Each directory commit bundles its header changes with its definitions, so every prefix builds and you can review/merge a directory at a time.
  • Completeness: the previous revision converted only ~378 of ~1162 K&R definitions (it had skipped those with multi-line argument comments, function-pointer parameters, or multi-line signatures). All of them are converted now.
  • Semantic fixes the stricter prototypes surfaced: explicit prototypes where bool/float/char arguments clashed with the old () form; forward typedefs for FontChar, TileType, and the netlist types; TechAddClient kept generic (its per-section callbacks vary) with opt typed int; callback casts where typed functions go into generic (*)() slots; and one latent bug fix — dbStampFunc was defined with two parameters but called recursively with one.

Verified with a clean-from-scratch GCC 16 build: 0 errors (only the same benign -Wdiscarded-qualifiers warnings as before), and tclmagic.so links.

If the format looks right on, say, the utils or database commit, I'm glad to adjust anything before you go through the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants