Why is passing a string literal into a char* arguament only sometimes a compiler error?

Posted by Brian Postow on Stack Overflow See other posts from Stack Overflow or by Brian Postow
Published on 2010-05-03T19:04:21Z Indexed on 2010/05/03 19:08 UTC
Read the original article Hit count: 255

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++