home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13364 < prev    next >
Encoding:
Text File  |  1992-09-08  |  2.3 KB  |  76 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!jvnc.net!nuscc!eletanjm
  3. From: eletanjm@nuscc.nus.sg (TAN JIN MENG)
  4. Subject: Re: Help!!!  Please Read this message!?!?!?!?!...
  5. Message-ID: <1992Sep9.042539.13326@nuscc.nus.sg>
  6. Organization: National University of Singapore
  7. References: <1992Sep9.041243.11893@nuscc.nus.sg>
  8. Date: Wed, 9 Sep 1992 04:25:39 GMT
  9. Lines: 65
  10.  
  11. eletanjm@nuscc.nus.sg (TAN JIN MENG) writes:
  12. : eletanjm@nuscc.nus.sg (TAN JIN MENG) writes:
  13. : : gmr6139@ultb.isc.rit.edu (G.M. Richard ) writes:
  14. : : : I can't get my compiler to do float-type variables.  I can do 
  15. : : : integers, and I can declare integers, but I can't either 
  16. : : : declare a real number or define a float variable.  This is no 
  17. : : : little typo here - the same programs work when compiled on a 
  18. : : : VAX, but when I compile this program with Turbo C, all I get 
  19. : : : is zeroes for floats.  Take a look:
  20. : : :  
  21. : : : /*  Variable Example */
  22. : : :  
  23. : : : #include <stdio.h>
  24. : : :  
  25. : : : #define apples  4
  26. : : : #define oranges 3.6
  27. : : :  
  28. : : : main()
  29. : : : {
  30. : : :         printf("\nApples = %d\nOranges = %f", apples, oranges);
  31. : : : }
  32. : : :  
  33. : : :  
  34. : : : output:
  35. : : :  
  36. : : : Apples=4
  37. : : : Oranges=0.000000           
  38. : : 
  39. : : Your compiler can't know what orange is... So it assumes that its an
  40. : : int. That's why the wrong result. Alternatives ...
  41. : : 
  42. : : 1) printf("\nApples = %d\nOranges = %f",(int)apples, (float)oranges);
  43. : : 
  44. : : 2) declare 
  45. : : const float oranges = 3.6;
  46. : Sorry, my explanation is obviously misleading. The examples should work
  47. : however.
  48.  
  49. Sigh.... Before someone writes to me flaming me, I'd better explain. I've
  50. encountered  a similar problem before (can't remember with which
  51. compiler though) and what happened was that the compiler was pushing
  52. ints as arguments.
  53.  
  54. BTW has anyone ever encountered a compiler (used intensively) that
  55. didn't have a bug of some kind or other?
  56. : : 
  57. : : :  
  58. : : :  
  59. : : : Any help on this problem would be greatly appreciated!!!!
  60. : : :  
  61. : : : 
  62. : : : -- 
  63. : : :   _  _                __                         gmr6139@ultb.isc.rit.edu
  64. : : :  /| /|  __  _/__/_   /__) ' __  /_  __ ,_  __/  gmr6139@george.cs.rit.edu
  65. : : : / |/ |_/-/__/__/____/ \__/_/___/ /_/-/_/__/_/  gmr6139@ritvax.isc.rit.edu
  66. : : : ____________________________________________  gmr6139@ritlav.isc.rit.edu
  67. : : 
  68. : : jin meng
  69. : jin meng
  70.  
  71.  
  72. jin meng
  73.