|
Small function I am trying to write is to take a string literal, and copy [part of] it to an array.
The array is fine, declared as an array and only accessed using indexing. But I cannot figure out how to search the string for particular sequences of char.
It's a string literal, so passed into the function as
foo("Hello World");
So the parameter is const char_t *. So how could I do anything with that, even find the length of it? I can't step the pointer through it, I can't even access it by index. Is such a thing as a string literal even legal?
void foo(const Octet *p)
{
/* ...Now what? p[n] is not legal because Octet * is not an array type,
and p++ would be a definite no-no.
*/
}
If I declared it as
void foo(const char_t c[])
would that be legitimate? It's legal C, I think, and it looks like an array declaration, but I don't see the difference between that and the previous. I can call it with
char_t *p;
...
foo(p);
or even
foo(NULL);
without a compiler warning (using gcc -ansi -pedantic -Wall; I'm sure PC-Lint would notice, but I don't have it here at home). So if the previous declaration was illegal, would this be also?
If I understand correctly, then it seems to me that even a simple function like strlen() could not be written, in a way that would be compliant. Is that, in fact, the case?
Frank
|