From d447dc63de506102559b23e4e48a07b189eace90 Mon Sep 17 00:00:00 2001
From: Andreas Scherer <andreas_github@freenet.de>
Date: Sat, 26 Apr 2025 10:38:15 +0200
Subject: [PATCH] Compile MMIX with C23.

$ CC='gcc-14 --std=c23' make all
issues tons of warnings (sic!) for the crude mixture of ANSI function
prototypes and K&R function definitions.

Obviously, I was of the mistaken apprehension that K&R function header
syntax would be deemed erroneous by the C23 standard; maybe in future
the curious ARGS(...) construct will fail.
---
 abstime.w    | 2 +-
 mmix-arith.w | 3 +--
 mmix-mem.w   | 2 +-
 mmix-pipe.w  | 8 ++++++--
 mmix-sim.w   | 5 ++---
 mmixal.w     | 2 +-
 6 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/abstime.w b/abstime.w
index 50d6aa9..6605ba1 100644
--- a/abstime.w
+++ b/abstime.w
@@ -18,7 +18,7 @@ hold more than 32 bits.
 #include <stdio.h>
 #include <time.h>
 @#
-main()
+int main()
 {
   printf("#define ABSTIME %ld\n",time(NULL));
   return 0;
diff --git a/mmix-arith.w b/mmix-arith.w
index 33fac8b..1ed3064 100644
--- a/mmix-arith.w
+++ b/mmix-arith.w
@@ -10,7 +10,6 @@
 \def\<#1>{\hbox{$\langle\,$#1$\,\rangle$}}\let\is=\longrightarrow
 \def\ff{\\{ff\kern-.05em}}
 @s ff TeX
-@s bool normal @q unreserve a C++ keyword @>
 @s xor normal @q unreserve a C++ keyword @>
 @s bignum int
 
@@ -33,9 +32,9 @@ suitable for loading with \MMIX\ simulators and assemblers.
 @c
 #include <stdio.h>
 #include <string.h>
+#include <stdbool.h>
 #include <ctype.h>
 @<Stuff for \CEE/ preprocessor@>@;
-typedef enum{@+false,true@+} bool;
 @<Tetrabyte and octabyte type definitions@>@;
 @<Other type definitions@>@;
 @<Global variables@>@;
diff --git a/mmix-mem.w b/mmix-mem.w
index c75ae16..1eb896a 100644
--- a/mmix-mem.w
+++ b/mmix-mem.w
@@ -24,7 +24,7 @@ read from and write to the memory-mapped addresses.
 @p
 #include <stdio.h>
 #include "mmix-pipe.h" /* header file for all modules */
-extern octa read_hex(); /* found in the main program module */
+extern octa read_hex @,@,@[ARGS((char *))@]; /* found in the main program module */
 static char buf[20];
 static char *kind[]={"byte","wyde","tetra","octa"};
 extern octa shift_left @,@,@[ARGS((octa y,int s))@];
diff --git a/mmix-pipe.w b/mmix-pipe.w
index 18bd86a..a66ed5c 100644
--- a/mmix-pipe.w
+++ b/mmix-pipe.w
@@ -7,7 +7,6 @@
 \def\Hex#1{\hbox{$^{\scriptscriptstyle\#}$\tt#1}} % experimental hex constant
 @s and normal @q unreserve a C++ keyword @>
 @s or normal @q unreserve a C++ keyword @>
-@s bool normal @q unreserve a C++ keyword @>
 @s xor normal @q unreserve a C++ keyword @>
 
 @* Introduction. This program is the heart of the meta-simulator for the
@@ -178,6 +177,11 @@ bypass the library names here.
 #define random my_random
 #define fsqrt my_fsqrt
 #define div my_div
+@#
+#define fadd my_fadd
+#define fsub my_fsub
+#define fmul my_fmul
+#define fdiv my_fdiv
 
 @ The amount of verbosity depends on the following bit codes.
 
@@ -257,7 +261,7 @@ void MMIX_run(cycs,breakpoint)
 }
 
 @ @<Type...@>=
-typedef enum {@!false, @!true, @!wow}@+bool; /* slightly extended booleans */
+#include <stdbool.h>
 
 @ @<Local var...@>=
 register int i,j,m;
diff --git a/mmix-sim.w b/mmix-sim.w
index eab80a5..386ed51 100644
--- a/mmix-sim.w
+++ b/mmix-sim.w
@@ -9,7 +9,6 @@
 \def\dts{\mathinner{\ldotp\ldotp}}
 \def\bull{\smallskip\textindent{$\bullet$}}
 @s xor normal @q unreserve a C++ keyword @>
-@s bool normal @q unreserve a C++ keyword @>
 
 @*Introduction. This program simulates a simplified version of the \MMIX\
 computer. Its main goal is to help people create and test \MMIX\ programs for
@@ -543,10 +542,10 @@ ReadErr  GETA t,1F              readerr: fputs("Trouble r...!",stderr)\cr
 1H       BYTE "Trouble reading!",\#a,0\cr
 }$$
 
-@* Basics. To get started, we define a type that provides semantic sugar.
+@* Basics. The standard type |bool| comes from \.{<stdbool.h>}.
 
 @<Type...@>=
-typedef enum {@!false,@!true}@+@!bool;
+#include <stdbool.h>
 
 @ This program for the 64-bit \MMIX\ architecture is based on 32-bit integer
 arithmetic, because nearly every computer available to the author at the time
diff --git a/mmixal.w b/mmixal.w
index ac03c69..b09bc14 100644
--- a/mmixal.w
+++ b/mmixal.w
@@ -955,7 +955,6 @@ necessary, to conform with the definitions found in {\mc MMIX-ARITH}.
 typedef unsigned int tetra;
   /* assumes that an int is exactly 32 bits wide */
 typedef struct { tetra h,l;} octa; /* two tetrabytes make one octabyte */
-typedef enum {@!false,@!true}@+@!bool;
 
 @ @<Glob...@>=
 extern octa zero_octa; /* |zero_octa.h=zero_octa.l=0| */
@@ -3163,6 +3162,7 @@ temporary use of global register~\$255.
 @c
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <ctype.h>
 #include <string.h>
 #include <time.h>
-- 
2.49.0

