diff --git a/2001/bellard/Makefile b/2001/bellard/Makefile index be3c93379..c4634b8d4 100644 --- a/2001/bellard/Makefile +++ b/2001/bellard/Makefile @@ -55,7 +55,7 @@ CSTD= -std=gnu99 # Some entries require 32-bitness: ARCH= -m32 # Some entries require 64-bitness: ARCH= -m64 # -ARCH= -m32 +ARCH= # Defines that are needed to compile # @@ -131,6 +131,11 @@ all: data ${TARGET} supernova deep_magic magic charon pluto ${PROG}: ${PROG}.c + @echo "WARNING: ${PROG}.c must be compiled as 32-bit to use with the entry itself;" + @echo "if you cannot use -m32 this will NOT work!" + ${CC} ${CFLAGS} -m32 $< -o $@ ${LIBS} + +${PROG}.otccex: ${PROG}.otccex.c ${CC} ${CFLAGS} $< -o $@ ${LIBS} # alternative executable diff --git a/2001/bellard/README.md b/2001/bellard/README.md index dcf37aaa6..407ba683a 100644 --- a/2001/bellard/README.md +++ b/2001/bellard/README.md @@ -24,17 +24,22 @@ linux or else some skill in resolving the portability issues. As it is it segfaults in 64-bit linux (and as expected macOS). He fixed an earlier segfault so that at least the file can be opened (but perhaps that will be wrong in i386 linux?) and he also changed some of the macro used to what they evaluate to but -mostly he kept it the same. He also fixed [bellard.otccex.c](bellard.otccex.c) -so it does not segfault and seemingly works okay (it did not work at all) but -still this appears to not work in 64-bit linux. See below portability notes. -Thank you Cody for your assistance! +mostly he kept it the same. + +Cody also fixed [bellard.otccex.c](bellard.otccex.c) so it does not segfault and +seemingly works okay (it did not work at all). The main problem was that some +ints were being used as pointers. Also the Fibonacci sequence (`fib()`) will +overflow at `n > 48` so this is checked prior to running the function. Either +way unfortunately this entry seems to not work in 64-bit linux or macOS. See +below portability notes. Thank you Cody for your assistance! + ### Portability notes: With a tip from [Yusuke Endoh](/winners.html#Yusuke_Endoh) we rediscovered the author's [web page for this program](https://bellard.org/otcc/) where it is stated that this will only work in i386 linux. The author also stated in the -remarks in this document that they used that they used [gcc +remarks in this document that they used [gcc 2.95.2](https://ftp.gnu.org/gnu/gcc/gcc-2.95.2/gcc-everything-2.95.2.tar.gz) but we don't know if that's relevant or not. diff --git a/2001/bellard/bellard.otccex.c b/2001/bellard/bellard.otccex.c index 901ecc28c..d2000a952 100644 --- a/2001/bellard/bellard.otccex.c +++ b/2001/bellard/bellard.otccex.c @@ -35,6 +35,7 @@ fact(n) /* local variables can be declared. Only 'int' type is supported */ int i, r; r = 1; + /* 'while' and 'for' loops are supported */ for(i=2;i<=n;i++) r = r * i; @@ -60,9 +61,9 @@ print_num(n, b) *p = c; p++; n = n / b; - /* 'break' is supported */ - if (n == 0) - break; + /* 'break' is supported */ + if (n == 0) + break; } while (p != tab) { p--; @@ -100,11 +101,13 @@ main(int argc, char **argv) return 1; } } - printf("fib(%d) = ", n); - print_num(fib(n), base); - printf("\n"); - - printf("fact(%d) = ", n); + printf("fib(%d) with base %d = ", base, n); + if (n > 48) { + printf("Overflow\n"); + } else { + print_num(fib(n), base); + } + printf("fact(%d) with base %d = ", base, n); if (n > 12) { printf("Overflow"); } else {