Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 4
    This code will not compile. It is neither legal nor safe to assign a pointer-to-const to a pointer-to-non-const. Commented Aug 13, 2011 at 7:28
  • 1
    "Returning a local object isn't accepted by many people" // No, this is rubbish. Returning a reference or pointer to a local object isn't accepted by the language or by compilers. But this is not the same. Commented Aug 13, 2011 at 15:52
  • 1
    And not only is this code non-valid, but even if you'd actually casted away the constness, it would be a horrendously silly thing to do. Commented Aug 13, 2011 at 15:52
  • Thanks Tomalak for your corrections and comments, please don't be too harsh, it's another idea, how to make it safer still depends on the OP's actual coding experience... Commented Aug 13, 2011 at 15:59
  • "const char* is also the same as char*, only different in the const_ness" that is as helpful as stating that "apples are the same as oranges, just different" Commented Nov 14, 2017 at 13:51