Hi, I am developing a http parser in C++. When I use the statement, char* data = "some string"; I receive the warning, 'warning : deprecated conversion from sting constant to char*'
kindly let me know why the statement is deprecated. I have just upgraded my OS(from fedora 8 to fedora 9) and I did not get the warning in my previous OS(fedora 8).
I also have a need to copy the string in character pointer as I do all the parsing using the data available in this pointer. I would also like to add that this warning is not shown when I use a 'const char*'(ie const char* data = "some string" ).
On Dec 1, 3:19 pm, mthread <rjk...@gmail.com> wrote:
> Hi, > I am developing a http parser in C++. When I use the statement, > char* data = "some string";
1. Use std::string
> I receive the warning, > 'warning : deprecated conversion from sting constant to > char*'
Ok. Compiler tells you that you try to convert const char* to char* because string literal "some string" is type of const char*. Of course, in common it's bad to convert const char* to char* because the variable of type const char* shouldn't be changed, but using char* you can change it. So, complier fairly warnings you.
> kindly let me know why the statement is deprecated. I have just > upgraded > my OS(from fedora 8 to fedora 9) and I did not get the warning > in my previous OS(fedora 8).
Probably, you complier has been upgraded with new version of distr.
> I also have a need to copy the string in character pointer as I > do all the parsing using the data available in this pointer. I would > also like to add that this warning is not shown when I use a 'const > char*'(ie const char* data = "some string" ).
In your case you can try
char* data = /* memory allocation */; strcpy(data, "some string");
On Dec 1, 3:35 pm, maverik <maverik.m...@gmail.com> wrote:
> Ok. Compiler tells you that you try to convert const char* to char* > because string literal "some string" is type of const char*. Of > course, in common it's bad to convert const char* to char* because the > variable of type const char* shouldn't be changed,
Strictly speaking, the value (of type T) to that pointer points can't be changed in case of const T*. It differs from T* const - constant pointer (not pointer to constant) where pointer can't be changed (but value it points to can be)
On 2008-12-01 07:35:05 -0500, maverik <maverik.m...@gmail.com> said:
> Ok. Compiler tells you that you try to convert const char* to char* > because string literal "some string" is type of const char*. Of > course, in common it's bad to convert const char* to char* because the > variable of type const char* shouldn't be changed, but using char* you > can change it.
There's nothing wrong with changing a variable of type const char*. The issue is changing the character data that it points to. Always try to keep this distinction clear. It will save you many headaches.
On Dec 1, 7:08 pm, Pete Becker <p...@versatilecoding.com> wrote:
> On 2008-12-01 07:35:05 -0500, maverik <maverik.m...@gmail.com> said:
> > Ok. Compiler tells you that you try to convert const char* to char* > > because string literal "some string" is type of const char*. Of > > course, in common it's bad to convert const char* to char* because the > > variable of type const char* shouldn't be changed, but using char* you > > can change it.
> There's nothing wrong with changing a variable of type const char*. The > issue is changing the character data that it points to. Always try to > keep this distinction clear. It will save you many headaches.
> Strictly speaking, the value (of type T) to that pointer points can't > be changed in case of const T*. It differs from T* const - constant > pointer (not pointer to constant) where pointer can't be changed (but > value it points to can be)