Skip to content

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

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

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

Conversation

@gonsolo

@gonsolo gonsolo commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

Converts 1162 old-style (K&R) function definitions to modern ANSI C prototypes across the tree, following the pattern of upstream PR RTimothyEdwards#487, and removes the -Wno-implicit-int flag that was suppressing the related warnings in the emscripten target.

GCC 16 defaults to C23, where () means (void) rather than "unspecified arguments", which broke the build independently of the K&R conversion. This adds -std=gnu17 (in defs.mak and the gcc SHLIB_CFLAGS block of scripts/configure[.in]) to restore C17 semantics so the many remaining legacy () declarations keep compiling.

Errors fixed after the conversion

  • Typed conflicting forward/header declarations — an empty () declaration is incompatible with a prototype whose parameters undergo default promotion (bool, float), so these needed explicit signatures.
  • Added struct-tag forward declarations (MagWindow, GrGlyph, TxCommand, NLNetList, cellUE, struct inarg) where the type wasn't visible, including to break circular header includes.
  • Reverted over-typed generic callback pointers (WindAddClient, WindSearch, GrLockPtr/GrUnlockPtr) back to () — their callbacks have intentionally varying return types and take no promotable scalar args.
  • Fixed genuine latent mismatches: extern int wind*Cmd() declarations that should be void, the DebugSet bool/int parameter mismatch, typed func pointers in CmdCD and PlowRules3, and comparator/callback casts for qsort, extEnumTilePerim, and the Tk/TOGL lock pointers.

Verification

  • Clean-from-scratch build (make clean + make -j -k): 0 errors, exit 0. Only warnings are 18 benign -Wdiscarded-qualifiers (const pointers passed to newly-typed prototypes that don't declare const; callees don't mutate).
  • tclmagic.so loads and magic::initialize -dnull -noconsole succeeds.
  • Functional smoke test against generated scmos.tech exercised the most heavily-converted files, all correct:
    • tech load (DBtech*.c)
    • paint poly/metal1/pcontact, with pcontact correctly forming polycontact (DBpaint.c, DBtpaint.c, DBtcontact.c)
    • drc check (DRCbasic.c, DRCtech.c)
    • extract allrealtest.ext (ExtBasic.c/ExtMain.c, incl. the extEnumTilePerim callback cast)
    • save → reload disk round-trip preserving all layer types (DBio.c read + write)

Not covered by the smoke test (compiled and loaded, but not executed): the routers (grouter/mzrouter/garouter/irouter), GDS/CIF/LEF I/O, plotting, and 3D. A valid-but-wrong type in one of those untested paths would not have been caught at runtime, though the clean build rules out most mis-typings (which surface as compile errors).

🤖 Generated with Claude Code

@gonsolo gonsolo force-pushed the modernize-knr-to-ansi-c branch from d32aa41 to fce7b5c Compare June 9, 2026 23:28
gonsolo and others added 26 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
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.

1 participant