Re: What does const char *s mean? is s a constant or *s?

From: pete (pfiland_at_mindspring.com)
Date: 01/24/05


Date: Mon, 24 Jan 2005 09:00:37 GMT

G Patel wrote:
>
> I've been looking at some code for string functions (certain
> implementation of them) and the non modified
> string is usually declared as a const char *s in the parameter list.

A const char *s in the parameter list means that you should
expect the function not to change the string that s points to,
even though the function still could do that
by casting away the const qualifier.

char *str_cpy(char *s1, const char *s2)
{
    char *const p1 = s1;
    
    do {
        *s1 = *s2++;
    } while (*s1++ != '\0');
    return p1;
}

-- 
pete


Relevant Pages

  • Re: Implementing strstr
    ... that string doesn't appear at all). ... const char* strstr(const char* haystack, const char* needle) ...
    (comp.programming)
  • curses mouse cut/paste on solaris2.9, hangs on select(). Works fine on aix and linux
    ... The program works fine on solaris, if the user inputs the string from ... const char *defaultText = NULL; ... void tstWprintw; ... int main ...
    (comp.unix.solaris)
  • Pinvoke reading files, returning char * values.
    ... const char* strInputFileName, ... back a string. ... public static extern bool GetXMLString(string inputFileName, ... StringBuilder output, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Whats wrong with the string?
    ... Then it is better to use "const char *" so that the ... >> putc() is a function to put a char on the serial console. ... the str could point beyond the end of your string. ... characters to characters. ...
    (comp.os.linux.embedded)
  • Re: Destroy a string
    ... "rossum" wrote in message ... const char overwriteChar = 'X'; ... The string is still on the heap, ... completely secure, all that is possible is to make the attacker's job ...
    (microsoft.public.dotnet.languages.csharp)