home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!rpi!usc!srhqla!quest!kdq
- From: kdq@quest.UUCP (Kevin D. Quitt)
- Newsgroups: comp.lang.c
- Subject: Re: Unwanted float to double conversion in variable length arg lists
- Message-ID: <3ukyXB4w165w@quest.UUCP>
- Date: Mon, 25 Jan 93 16:36:13 PST
- References: <C18924.2yp@inews.Intel.COM>
- Reply-To: srhqla!quest!kdq
- Organization: Job quest (805) 251-8210, So Cal: (800) 400-8210
- Lines: 42
-
- 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.
- > Consider:
- >
- > #include <stdarg.h>
- >
- > void func(int num,...) {
- ...
- > }
- >
- > int main() {
- > func(4,1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0);
- > func(2,(float)1.0,(float)1.0,(float)2.0,(float)2.0);
- > }
- >
- > I have explicitly typecast a real number to (float), and it still ends
- > up on the stack as a double!
-
- Yep. Casting something as float does not prevent the automatic
- promotion to double when no function prototype is in scope. Since
- your function func does not specify floats, C *must* convert to
- doubles. Make sense?
-
- ffunc( float foo )
- {
- ...
- }
- main()
- float f = 3.14;
-
- ffunc( (int)f )
- }
- What should the compiler do? Completely ignore the typecast or
- convert f to an int (should get a warning about possible loss of
- precision), and then back to a float as the function prototype
- requires?
-
-
- _
- Kevin D. Quitt 96.37% of all statistics are made up. srhqla!quest!kdq
-