Anyone on ANSI standard C - (nf)
Guy Harris
guy at rlgvax.UUCP
Fri Feb 10 15:17:46 AEST 1984
> I have a question about the effects of specifying parameter types in
> the ANSI C standard. What will the exact effect be when the type of an
> actual parameter differs from the type given in the declaration? Seems to
> me that while silently casting is usually the right thing, in some cases
> the compiler should issue warnings because the odds are good the
> user is making a mistake. I think the compiler should cast silently
> if the declared and actual types are both arithmetic, regardless of
> length or signed/unsigned distinctions (leave warnings about lost
> accuracy to lint), or if the declared type is a pointer of any type and the
> actual parameter is the constant 0, but warn the user about everything
> else (e.g., using an int or char* where a FILE* was expected).
That's actually an implementation question to some degree; the Portable C
Compiler already issues warnings for the implicit conversions you mention.
I.e., if you have
int foo;
char *bar;
FILE *bletch;
foo = bar;
bletch = bar;
you will get "Illegal combination of pointer and integer" for the first and
"Illegal pointer combination" for the second. Any PCC-based implementation
of ANSI C would probably do exactly this, which is what you suggest.
Guy Harris
{seismo,ihnp4,allegra}!rlgvax!guy
More information about the Comp.lang.c
mailing list