Function argument type conversions...

K.LAUX rkl1 at hound.UUCP
Mon Oct 17 03:06:39 AEST 1988


In article <8810111921.AA21683 at ucbarpa.Berkeley.EDU>, U23405 at UICVM.Berkeley.EDU (Michael J. Steiner) writes:
> Someone recently said:
> >My questions are:
> >
> >    1. Is it illegal to declare a parameter to be of type `char'?
> >    2. If not, is it valid to treat the parameter as type `int'?
> >    3. If so, what does the unary `&' operator do to such a variable?
> >    4. Where is this addressed in K&R I?
> >    5. Where is this addressed in the Draft (assuming no prototypes)?
> ----------
> What I would like to know is if all function parameters (formal and actual)
> agree in type, will there still be problems with taking the address of a
> passed variable, (among other little things)?
> 
>                                                  Michael Steiner
>                                                  Email: U23405 at UICVM.BITNET


	By definition, all function calls are by *value*.  Therefore it is
permissible to take the address of any argument.  The address one will get
is *not* the original storage of the variable, but one from the *stack*.

	If you really want to modify the original storage location, then you
would pass the *address* of the variable as an argument to the function.

	As far as (1) is concerned, it is not illegal to declare a parameter
as type 'char'.  What you are doing is telling the compiler to treat the
parameter as a 'char' within the scope of the function.  Therefore, for (2),
it is *not* proper to treat it as an 'int' if you haven't declared it as an
'int' (although it was converted to an 'int' and pushed onto the stack before
the function was called)

--rkl



More information about the Comp.lang.c mailing list