Path: utzoo!utgpu!watmath!att!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!ncrlnk!ncr-sd!hp-sdd!hplabs!hp-ses!hpcuhb!hpcllla!hpclisp!hpclwjm!walter
From: walter@hpclwjm.HP.COM (Walter Murray)
Newsgroups: comp.lang.c
Subject: Re: passing *char parameters by reference
Message-ID: <660051@hpclwjm.HP.COM>
Date: 14 Aug 89 16:37:54 GMT
References: <1424@novavax.UUCP>
Organization: Hewlett-Packard Calif. Language Lab
Lines: 35

Karl Heuer writes:

>In article <660050@hpclwjm.HP.COM> walter@hpclwjm.HP.COM (Walter Murray) writes:
>>If you use function prototypes, an ANSI-conforming compiler will also
>>catch this kind of error.

>Or it might silently "fix" it by doing an automatic conversion from the actual
>argument type to the formal parameter type.  Hopefully, any reasonable ANSI C
>compiler will at least have an option to warn about such constructs.

Are you sure?

For a function call, the dpANS has a constraint which requires that "each
argument shall have a type such that its value may be assigned to an object
with the unqualified version of the type of its corresponding parameter."
(3.3.2.2)

Given:

   void swap (char *x, char *y) { }
   main()
   {
      char *a; char *b;
      swap( &a, &b );
   }

Each argument in the call has type "pointer to pointer to char."
The corresponding parameters have type "pointer to char."  Assignments
would not be legal (3.3.16.1).  Because a constraint has been violated,
an ANSI-conforming compiler will produce a diagnostic message.  It may
well "fix" the mistake, but I don't think it can do so silently.

Walter Murray
Not an X3J11 answer, of course
----------------------------------------------------------------------