This was taken from the following:
And I quote:
"Well, that's also ok for char**, since string literals are of type
char * in c. The general idea still stands, though.
The thing that irritates me is that despite all this, it's _trivial_
to violate const in C without resorting to all this.
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, but the prototype is defined as the following:
char *strchr(const char *s, int c);
When foo gets de-referenced (ie *foo), how come the compiler doesn't
complain about the difference between 'int' and 'char'?
Thanks in advance.
Chad
And I quote:
"Well, that's also ok for char**, since string literals are of type
char * in c. The general idea still stands, though.
The thing that irritates me is that despite all this, it's _trivial_
to violate const in C without resorting to all this.
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, but the prototype is defined as the following:
char *strchr(const char *s, int c);
When foo gets de-referenced (ie *foo), how come the compiler doesn't
complain about the difference between 'int' and 'char'?
Thanks in advance.
Chad
Comment