Moving the kernel to modern C
Moving the kernel to modern C
Posted Feb 25, 2022 18:44 UTC (Fri) by nybble41 (subscriber, #55106)In reply to: Moving the kernel to modern C by Wol
Parent article: Moving the kernel to modern C
In C89 and GNU89 declarations must occur before statements within each block. C89 additional requires initializers to be compiler-time constants. However, it's not as if this equivalent GNU89 code is any easier to follow:
#include <stdio.h>
#include <unistd.h>
int blah(long x, int j)
{
long i = x ? x : -1;
int k = i;
{
int i;
for (i = 1; i < j; i++) {
k += i * 2;
{
char i = (k & 1) ? 'O' : 'E';
{
int pid = getpid();
printf("i=%d j=%d pid=%d\n", i, j, pid);
}
}
}
}
return k;
}
The real lessons here are "use meaningful names" and "avoid shadowing".
