passing *char parameters by reference

Walter Murray walter at hpclwjm.HP.COM
Tue Aug 15 02:37:54 AEST 1989


Karl Heuer writes:

>In article <660050 at hpclwjm.HP.COM> walter at 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
----------------------------------------------------------------------



More information about the Comp.lang.c mailing list