Thread: c_str like function implementation

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #27
    Registered User
    Join Date
    Nov 2007
    Posts
    11
    hello" is a string literal. It is constant and cannot be changed. Therefore, this second line of code is illegal:

    const char* s = "hello";
    OK now I filaly get it. My stupid mistake that I thought that this is wrong because of the pointer to a constant string ( didn't know that that was legal).

    So I don't understand why you think that code "can create problems with the pointer". Can you elaborate?
    I once had some problems in one test case ( don't remember anymore what it was ). In all the other test cases it worked so perhaps I made a mistake somewhere else back then.

    I thouhth that the problem was caused because if you have a pointer of some length and then add aditional characters over the allocated size it could overwrite some other part of the memory that contains other data. Is that not so?
    Last edited by DoMeN; 02-13-2008 at 01:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Brand new to C need favor
    By dontknowc in forum C Programming
    Replies: 5
    Last Post: 09-21-2007, 10:08 AM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM