home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20073 < prev    next >
Encoding:
Internet Message Format  |  1993-01-22  |  1.8 KB

  1. Path: sparky!uunet!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
  2. From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Unwanted float to double conversion in variable length arg lists?
  5. Date: 22 Jan 1993 15:43:12 GMT
  6. Organization: TH Darmstadt
  7. Lines: 26
  8. Distribution: world
  9. Message-ID: <1jp4mgINN11m6@rs2.hrz.th-darmstadt.de>
  10. References: <C18924.2yp@inews.Intel.COM>
  11. NNTP-Posting-Host: rbhp65.rbg.informatik.th-darmstadt.de
  12.  
  13. In article <C18924.2yp@inews.Intel.COM>, dmarer@td2cad.intel.com (Dennis Marer) writes:
  14. > I've got a curious problem when passing floats in a variable length argument
  15. > list...they are automatically converted to doubles, EVEN when I typecast.
  16.  
  17. [....]
  18.  
  19. > I have explicitly typecast a real number to (float), and it still ends 
  20. > up on the stack as a double!  This is the same on various compilers,
  21. > including Gnu C and IBM C for the AIX operating system.  This seems incorrect
  22. > to me, and I'm afraid that if I assume it how things are supposed to be
  23. > implemented, I'll have portability problems.
  24. > Is this correct? Are all ANSI C compilers implemented this way?  --> Why?
  25.  
  26. If there's no prototype, or in a variable length argument list, chars and
  27. shorts get converted to int, and floats to double. This behavior is correct
  28. ANSI. Why is it done this way ? Cause it's the way pre-ANSI compilers did
  29. it. This was implemented this way, so you hadn't to typecast all arguments
  30. to int, when calling a function that expected ints. Normally an ANSI compiler
  31. does this real nice, if you use prototypes, but it has to fail in variable
  32. length arguments. 
  33.  
  34. -- 
  35. Walter Misar                                | It is impossible to enjoy
  36. misar@rbg.informatik.th-darmstadt.de        | idling thoroughly unless
  37.                                             | one has plenty of work to do.
  38.