Why is passing a string literal into a char* arguament only sometimes a compiler error?
- by Brian Postow
I'm working in a C, and C++ program. We used to be compiling without the make-strings-writable option. But that was getting a bunch of warnings, so I turned it off.
Then I got a whole bunch of errors of the form "Cannot convert const char* to char* in argmuent 3 of function foo". So, I went through and made a whole lot of changes to fix those.
However, today, the program CRASHED because the literal "" was getting passed into a function that was expecting a char*, and was setting the 0th character to 0. It wasn't doing anything bad, just trying to edit a constant, and crashing.
My question is, why wasn't that a compiler error?
In case it matters, this was on a mac compiled with gcc-4.0.