Merge pull request #929 from xexyl/2001-bellard-otccex
More fixes in 2001/bellard
This commit is contained in:
3 files changed
+24
-17
No files matched your search
@@ -113,8 +113,8 @@ ENTRY= bellard
|
|||||||
PROG= ${ENTRY}
|
PROG= ${ENTRY}
|
||||||
#
|
#
|
||||||
OBJ= ${PROG}.o
|
OBJ= ${PROG}.o
|
||||||
DATA= bellard.otccex.c
|
DATA=
|
||||||
TARGET= ${PROG}
|
TARGET= ${PROG} ${PROG}.otccex
|
||||||
#
|
#
|
||||||
ALT_OBJ=
|
ALT_OBJ=
|
||||||
ALT_TARGET=
|
ALT_TARGET=
|
||||||
@@ -134,7 +134,7 @@ all: data ${TARGET}
|
|||||||
${PROG}: ${PROG}.c
|
${PROG}: ${PROG}.c
|
||||||
@echo "WARNING: ${PROG}.c must be compiled as 32-bit to use with the entry itself;"
|
@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!"
|
@echo "if you cannot use -m32 this will NOT work!"
|
||||||
${CC} ${CFLAGS} -m32 $< -o $@ ${LDFLAGS}
|
${CC} ${CFLAGS} -m32 $< -o $@ ${LDFLAGS} || :
|
||||||
|
|
||||||
${PROG}.otccex: ${PROG}.otccex.c
|
${PROG}.otccex: ${PROG}.otccex.c
|
||||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ main(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
print_num(fib(n), base);
|
print_num(fib(n), base);
|
||||||
}
|
}
|
||||||
printf("fact(%d) with base %d = ", base, n);
|
printf("\nfact(%d) with base %d = ", base, n);
|
||||||
if (n > 12) {
|
if (n > 12) {
|
||||||
printf("Overflow");
|
printf("Overflow");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+20
-13
@@ -904,20 +904,27 @@ sings [Ten in the Bed](https://allnurseryrhymes.com/ten-in-the-bed/).
|
|||||||
|
|
||||||
## [2001/bellard](2001/bellard/bellard.c) ([README.md](2001/bellard/README.md]))
|
## [2001/bellard](2001/bellard/bellard.c) ([README.md](2001/bellard/README.md]))
|
||||||
|
|
||||||
Cody at least partially fixed this but he notes that this will not work without
|
Cody fixed this to compile with clang but according to the author this will not
|
||||||
(according to the author) i386 linux or else some skill in resolving the
|
work without i386 linux. It generates i386 32-bit code (not bytecode) but
|
||||||
portability issues. As it is it segfaults in 64-bit linux (and as expected
|
unfortunately it will not work without i386 linux. Cody fixed an earlier
|
||||||
macOS). He fixed an earlier segfault so that at least the file can be opened
|
segfault so that it can at least now open the file and he also changed some of
|
||||||
(but perhaps that will be wrong in i386 linux / older C?) and he also changed
|
the macros used to what they translate to but mostly it was kept the same.
|
||||||
some of the macro used to what they evaluate to but mostly he kept it the same.
|
Yusuke added another change (see below) to make it even more portable across
|
||||||
|
compilers besides what Cody did.
|
||||||
|
|
||||||
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
|
Cody also fixed the [supplementary
|
||||||
ints were being used as pointers. Also the Fibonacci sequence (`fib()`) will
|
bellard.otccex.c](2001/bellard/bellard.otccex.c) so it does not segfault and
|
||||||
overflow at `n > 48` so this is checked prior to running the function just like
|
works as well. The main problem was that some ints were being used as pointers.
|
||||||
the author did for the factorial (overflowing at `>12`). Either way
|
This includes, for example, an int used as a `char *`, an int used as a function
|
||||||
unfortunately this entry seems to not work in 64-bit linux or macOS. See below
|
pointer and an int to access `argv` as well as there being invalid access to
|
||||||
portability notes as well as another fix in this entry by Yusuke.
|
`argv`. He updated the Makefile so that this program will compile by default.
|
||||||
|
|
||||||
|
Also the Fibonacci sequence (`fib()`) will overflow at `n > 48` so this is
|
||||||
|
checked prior to running the function just like the author did for the factorial
|
||||||
|
(overflowing at `>12`). Either way unfortunately this entry seems to not work in
|
||||||
|
64-bit linux or macOS. See below portability notes as well as another fix in
|
||||||
|
this entry by Yusuke.
|
||||||
|
|
||||||
### Portability notes:
|
### Portability notes:
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user