From 6a3d3e78e063096d4ad17e217bac3ad33fbfa81a Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Thu, 24 Dec 2020 14:41:14 -0500 Subject: [PATCH] expand the known issues list --- known_issues.org | 140 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 17 deletions(-) diff --git a/known_issues.org b/known_issues.org index 8d17aa1..6734ee8 100644 --- a/known_issues.org +++ b/known_issues.org @@ -1,21 +1,12 @@ M2-Planet is subset of the C programming language. -Mostly eliminating features that have yet to be proven useful in building compilers, linkers or assemblers. +Mostly by eliminating features that have yet to be proven useful in building compilers, linkers or assemblers. -* Global variables -** Assignment -*** struct initialization -M2-Planet doesn't support static initialization for structs yet. - -Simply because time hasn't been made available for the effort. - -Patches for adding support are welcome. - -*** AMD64 & AArch64 int initialization wrong +* AMD64 & AArch64 int initialization wrong right now the code in cc_core.c in the function void program() simply doesn't output the correct output for AArch64 or AMD64. As the function should numerate the string global_token to determine if the leading 32bits should be 0 or 0xFFFFFFFF and output %0 or %0xFFFFFFFF accordingly. -**** example of failing code +** example of failing code #include #include #include @@ -44,10 +35,9 @@ int main() return 0; } -* Arrays -** multidimensional arrays return wrong results +* multidimensional arrays return wrong results -*** example of failing code +** example of failing code #include char** env_argv; @@ -66,20 +56,97 @@ int main(int argc, char** argv) run with: ./example 12345 abcdef ABCDEF -*** work around code +** work around code char getargchar(int n, int k) { char *tmp = env_argv[n]; return tmp[k]; } +* Pointer arithmetic wrong +It isn't uncommon for complex C programs to iterate over an array using a pointer. + +** example of failing code +#include +#include + +void walk_array(char** array, char** array_end) +{ + char** i = array; + while(i < array_end) + { + fputs(i[0], stdout); + fputc('\n', stdout); + i = i + 1; + } +} + +int main() +{ + char** array = calloc(10, sizeof(char*)); + array[0] = "hello"; + array[1] = "world"; + array[2] = "how"; + array[3] = "are"; + array[4] = "you"; + array[5] = "today"; + array[6] = "I"; + array[7] = "am"; + array[8] = "doing"; + array[9] = "fine"; + walk_array(array, array + 10); + return 0; +} + +** work around code +#include +#include + +// CONSTANT pointer_size sizeof(char*) +#define pointer_size 1 + +void walk_array(char** array, char** array_end) +{ + char** i = array; + while(i < array_end) + { + fputs(i[0], stdout); + fputc('\n', stdout); + i = i + pointer_size; + } +} + +int main() +{ + char** array = calloc(10, sizeof(char*)); + array[0] = "hello"; + array[1] = "world"; + array[2] = "how"; + array[3] = "are"; + array[4] = "you"; + array[5] = "today"; + array[6] = "I"; + array[7] = "am"; + array[8] = "doing"; + array[9] = "fine"; + walk_array(array, array + (10 * pointer_size)); + return 0; +} + +* struct initialization +M2-Planet doesn't support static initialization for structs yet. + +Simply because time hasn't been made available for the effort. + +Patches for adding support are welcome. + * typedef doesn't work M2-Planet doesn't support this function yet as the time for its development has not been allocated yet. Patches are welcome * C style function pointers -M2-Planet supports universal function pointers FUNCTION +M2-Planet supports universal function pointer FUNCTION Simply delete the typedef and the code works fine in M2-Planet ** example of failing code @@ -113,3 +180,42 @@ int main () fun_make_cell_.name = "bar\n"; fun_make_cell_.function(); } + +* logical and do not short circuit +Both sides of && evaluate because it hasn't been shown to be worth the effort of implementation of short-circuit logic + +** example of failing code +#include +#include + +int boom() +{ + exit(EXIT_FAILURE); +} + +int main(int argc, char* argv) +{ + if((0 == argc) && boom()) + { + fputs("impossible code\n", stderr); + } + return 0; +} + +** work around code +#include +#include + +int boom() +{ + exit(EXIT_FAILURE); +} + +int main(int argc, char* argv) +{ + if(0 == argc) + { + if(boom())fputs("impossible code\n", stderr); + } + return 0; +}