home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / linux / 23408 < prev    next >
Encoding:
Text File  |  1993-01-09  |  2.2 KB  |  63 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
  3. From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
  4. Subject: Re: Kernel FP Math bug?
  5. Message-ID: <1993Jan9.234732.9594@klaava.Helsinki.FI>
  6. Organization: University of Helsinki
  7. References: <1993Jan9.144510.9590@walter.cray.com> <1993Jan09.224846.12403@rs6000.cmp.ilstu.edu>
  8. Date: Sat, 9 Jan 1993 23:47:32 GMT
  9. Lines: 52
  10.  
  11. jliddle@rs6000.cmp.ilstu.edu (Jean Liddle) writes:
  12. >Also, my kernel is compiled without math emulation, if that helps in
  13. >narrowing down the possibilities ...
  14.  
  15. Gee, and I get core dumps with the same code on a Sun.  Perhaps it is
  16. a very serious, very far spread problem with gcc?
  17.  
  18. No, I don't think so either.  The program that is supposed to exhibit
  19. the problem has two severe problems, and a couple of less severe
  20. problems.  Here is the original program again:
  21.  
  22.     main(int argc, char *argv)
  23.     {
  24.       double f;
  25.  
  26.       f = atof(argv[1]);
  27.       printf("The answere is %f\n", f);
  28.     }
  29.  
  30. The severe problems are that argv has the wrong type and that atof is
  31. not declared anywhere.  Since argv has the wrong type (pointer to
  32. char, instead of pointer to pointer to char), it behaves badly as a
  33. result.  This results in the core dump.
  34.  
  35. Since the function atof is not declared anywhere, it is assume to have
  36. the default type int.  The correct type is double, so it has to be
  37. declared.  The corrected program looks like this:
  38.  
  39.     double atof();
  40.     main(int argc, char **argv)
  41.     {
  42.       double f;
  43.  
  44.       f = atof(argv[1]);
  45.       printf("The answere is %f\n", f);
  46.     }
  47.  
  48. and this does, indeed, run without problems.
  49.  
  50. The less severe problems are that there is no prototype for printf in
  51. scope (include <stdio.h> for this), and the program does not return a
  52. value to the operating system (put a return or an exit to the end of
  53. main to fix this).
  54.  
  55. I just love people who scream "compiler bug" or "operating system bug"
  56. when they can't see what's wrong with their own code.  Both compilers
  57. and OS's have bugs (I know they do, I've found a number myself), but
  58. the probability of finding one is fairly small.
  59.  
  60. --
  61. Lars.Wirzenius@helsinki.fi  (finger wirzeniu@klaava.helsinki.fi)
  62. While you teach one ignorant fool Usenet netiquette, two more join the net.
  63.