From: Goswin v. B. <gos...@we...> - 2008-08-27 09:04:45
|
Miklos Szeredi <mi...@sz...> writes: > On Thu, 07 Aug 2008, Goswin von Brederlow wrote: >> Now I see that I violate the const-ness in path but it causes the >> following call sequence: >> >> create("/foo", mode, fi); >> getattr("", buf); >> >> and that gave the wrong attributes. Took me ages to find the problem >> as g++ also doesn't warn about the violation of const. > > Mmm, lots of people run into this. How come g++ doesn't warn on const > violation? I thought that C++ was supposed to have _stricter_ type > checking than C. In my case the problem is char *foo = index(path, '/'); and index is declared as char *index(const char *s, int c); The use of index looses the const-ness of the pointer. In C there is no other way for index to work for both const char* and char* but in C++ there could be 2 declarations: const char *index(const char *s, int c); char *index(char *s, int c); Unfortunately <cstring> does not contain those. I bet there are a number of other C functions with this "bug". MfG Goswin |