Very elementary question concerning indirection

Trip Martin night at pawl.rpi.edu
Fri Feb 16 16:57:02 AEST 1990


david at csource.oz.au (david nugent) writes:


> > printf( "%c\n",*(strchr(string,40)) );   <---- line in question
> >
> > If the "line in question" is commented out, the program compiles with
> > one warning on line 7 (This is in Vax Ultrex C, no warning is given in
> > Turbo C). What is wrong with the "line in question". Also, what does this
> > warning mean?


>It means I _like_ that compiler! :-)

>Hmm, one clever enough to understand printf() style format strings is rather 
>nice.  It must know it's looking for a char there..

>I'm not too surprised TC passes it with no comment.  printf() is defined to 
>have a variable number of arguments, and no type checking at all is in 
>effect.

You're missing the problem here.  The compiler is complaining about
dereferencing an integer.  Now you and I know that strchr() returns a
pointer to a char, but in this case the compiler doesn't know that
so it assumes that strchr() returns a pointer to a char, so it is
correct in complaining about the dereference.

The error message has nothing to do with the semantics of printf.

-- 

Trip Martin
night at pawl.rpi.edu



More information about the Comp.lang.c mailing list