On Wed, 2005-11-23 at 13:13 +1100, Benno wrote:
> On Tue Nov 22, 2005 at 19:47:51 -0600, [EMAIL PROTECTED] wrote:

> >-----------------------------
> >char* somefunction()
> >{
> >       char string2[] = "some words";
> >       return string2;
> >}
> >--------------------------------------
> >doesn't
> 
> In this case you have initialised a stack value to some initial
> value. Here the memory is on the stack.

Which means the memory may not be addressable at all (proper memory
management) or it may be addressed but may well be overwritten by
something in between, even just returning from the function call.

This will probably work then not and you will wonder why.

> >
> >>char *string2 = "some words\0";
> >>   string1 = (char *)calloc(strlen(string2 + 1), sizeof (char));
> >
> >strlen (string2 + 1) = strlen ("ome words");
> >
> >why do you want to do that?
> >
> 
> Errr, that wasn't meant to be C, just saying that
> 
> strlen(string2 + 1) is equvilant to strlen("ome words");

char * pointer = "Some String"

pointer + 1 refers to the "o" in the some string so:

strlen( pointer + 1 ) will equal 10
strlen( pointer ) + 1 will equal 12

One is right and one is totally wrong.

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to