Thread: Are these cost char [] static??

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    1

    Are these cost char [] static??

    I found this in our code base today, I wonder is this entirely safe or are we depending on the bahavior of the compiler here that these strings are static, and thus around after the function returns?

    Code:
    //-----------------------------------------------------------------------------
    const char* ProcessModule::DetermineLogFilePrefix()
    {
      if (this->Options)
        {
        switch (this->Options->GetProcessType())
          {
        case Options::CLIENT:
          return NULL; // don't need a log for client.
        case Options::SERVER:
          return "ServerNodeLog";
        case Options::RENDER_SERVER:
          return "RenderServerNodeLog";
        case Options::DATA_SERVER:
          return "DataServerNodeLog";
          }
        }
      return "NodeLog";
    }

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Yes, that's safe. Literal strings aren't deleted when they go out of scope. I believe they're stored in a different part of memory than regular variables (not the stack or heap).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  2. Need help on understandind arrays
    By C++mastawannabe in forum C++ Programming
    Replies: 9
    Last Post: 06-16-2007, 10:50 PM
  3. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  4. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM