Re: Sort of mystified from an earlier thread



In article <1130637106.638913.16850@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Chad <cdalten@xxxxxxxxx> wrote:
>...const char foo[] = "mystring";
>char *constviol = strchr(foo,*foo); "
>
>What I don't get is that that 'const char f[]="mystring" ' is defined
>as a char,

No, it's defined as a conat char[9]. I'm assuming you mean
*f but that's a const char.

> but the prototype is defined as the following:
>
>char *strchr(const char *s, int c);

Correct.

>When foo gets de-referenced (ie *foo), how come the compiler doesn't
>complain about the difference between 'int' and 'char'?

Because it is one of the implicit conversions. You can do this with
no problem:

const char c = 'x';
int i;

i = c;

A similar thing happens during argument passing, since the prototype
specifically says the argument should be an int.

Why it is an int is a seperate story, but no doubt has to do
with the fact that routines such as getchar return int's (as
they, for better or worse, accomodate for the returned character
_and_ signals such as EOF).
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
.



Relevant Pages