home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
- From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
- Subject: Re: Kernel FP Math bug?
- Message-ID: <1993Jan9.234732.9594@klaava.Helsinki.FI>
- Organization: University of Helsinki
- References: <1993Jan9.144510.9590@walter.cray.com> <1993Jan09.224846.12403@rs6000.cmp.ilstu.edu>
- Date: Sat, 9 Jan 1993 23:47:32 GMT
- Lines: 52
-
- jliddle@rs6000.cmp.ilstu.edu (Jean Liddle) writes:
- >Also, my kernel is compiled without math emulation, if that helps in
- >narrowing down the possibilities ...
-
- Gee, and I get core dumps with the same code on a Sun. Perhaps it is
- a very serious, very far spread problem with gcc?
-
- No, I don't think so either. The program that is supposed to exhibit
- the problem has two severe problems, and a couple of less severe
- problems. Here is the original program again:
-
- main(int argc, char *argv)
- {
- double f;
-
- f = atof(argv[1]);
- printf("The answere is %f\n", f);
- }
-
- The severe problems are that argv has the wrong type and that atof is
- not declared anywhere. Since argv has the wrong type (pointer to
- char, instead of pointer to pointer to char), it behaves badly as a
- result. This results in the core dump.
-
- Since the function atof is not declared anywhere, it is assume to have
- the default type int. The correct type is double, so it has to be
- declared. The corrected program looks like this:
-
- double atof();
- main(int argc, char **argv)
- {
- double f;
-
- f = atof(argv[1]);
- printf("The answere is %f\n", f);
- }
-
- and this does, indeed, run without problems.
-
- The less severe problems are that there is no prototype for printf in
- scope (include <stdio.h> for this), and the program does not return a
- value to the operating system (put a return or an exit to the end of
- main to fix this).
-
- I just love people who scream "compiler bug" or "operating system bug"
- when they can't see what's wrong with their own code. Both compilers
- and OS's have bugs (I know they do, I've found a number myself), but
- the probability of finding one is fairly small.
-
- --
- Lars.Wirzenius@helsinki.fi (finger wirzeniu@klaava.helsinki.fi)
- While you teach one ignorant fool Usenet netiquette, two more join the net.
-