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