How to declare constant strings in C/C++?
I have a function that returns an error string. The value is actually the address of an internal data member (I don't want to allocate memory and copy the string - I don't trust that the "user" would free it), and consequently, I don't want anyone to screw around with its contents. So how do I declare the return value so that the contents of the string are constant as opposed to the pointer's value being constant? (I hope that made sense)
const char *foo()
(const char) *foo()
<edit>
typedef const char c_char
typedef c_char * c_string
That seems a bit klunky though...
</edit>
I hate having to ask (it seems such a fundamental thing) but I rarely use constant strings other than literals in my code.
Last edited by Dark_Helmet; 05-28-2004 at 06:45 PM.
|