[vox-tech] totally confused about C promotion
Micah Cowan
vox-tech@lists.lugod.org
Mon, 14 Jan 2002 16:28:32 -0800
On Mon, Jan 14, 2002 at 03:16:18PM -0800, Peter Jay Salzman wrote:
> from kernighan and ritchie, page 45:
>
> For example, the library routine sqrt expects a double argument, and
> will produce nonsense if inadvertantly handed something else.
>
<snip>
> what happens when you hand a long double to a math function which
> expects a double? i can't find any rules for "demotion" in K+R.
> does code2.c work by accident or is there a concept of demoting floating
> points to a narrower width when the function expects them to be
> narrower?
Do you have the "old" K&R, or the second edition? The old one was
before prototypes were invented, so it'd make sense for them to say
something like that. Prototypes will force the argument to be the
correct type, automatically converting them. Of course, this doesn't
apply to variadic functions such as the printf() examples.
Micah