Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!sun!amdcad!nucleus!tim From: tim@nucleus.amd.com (Tim Olson) Newsgroups: comp.os.minix Subject: Re: C SYNTAX QUESTION Message-ID: <29807@amdcad.AMD.COM> Date: 10 Apr 90 12:42:00 GMT References: <16304@nigel.udel.EDU> Sender: news@amdcad.AMD.COM Reply-To: tim@amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc., Austin, Texas Lines: 59 Summary: Expires: Sender: Followup-To: In article <16304@nigel.udel.EDU> HBO043%DJUKFA11.BITNET@cunyvm.cuny.edu (Christoph van Wuellen) writes: | somenone pointed out that with my recetly posted C-compiler, the | funcion | test(a) char a; | { | write (1,&a,1); | } | passes a pointer to an integer to write (since a is really an integer) | write emits something else than you'd expected - it is easy to ,,fix'' | in the compiler, BUT WHAT ABOUT | test(a) float a; | { | test1(&a); | } | This certainly passes a pointer to a double, and this can't be changed. | So I ask the C Syntax experts - what do you think a compiler should do | in both cases? | C.v.W. In non-ANSI C (and in ANSI C, in the absence of prototypes), function parameters of type "char" and "short" are widened to int, and function parameters of type "float" are widend to "double" by the caller: char c = 5; f(c); will pass an int with value 5 to f. If f is declared as: f(i) int i; This is fine. However, if f is declared as f(c) char c; then the incoming integer must be converted to a character by the compiler, then treated like a local variable declared as type "char". Likewise, if a "float" is passed and converted to double by the caller, then f(d) double d; will work fine. If f is declared f(d) float d; then the incoming parameter must be converted from double-precision to single-precision on entry by the compiler. -- Tim Olson Advanced Micro Devices (tim@amd.com)