Re: return a string
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Sat, 30 Apr 2005 19:45:29 GMT
"Emmanuel Delahaye" <emdel@xxxxxxxxxxxxxx> writes:
> Nascimento wrote on 29/04/05 :
[...]
>> for( i = 0; i < num-1; i++ )
>> strcpy(tralha, strcat(tralha,"#"));
>
> Note that this is dangerous. The order of execution of the parameters
> is defined by the implementation. BTW, chances are that strcat() is
> called before strcpy().
Actually, I think it's guaranteed that strcat() will be called before
strcpy(). The order of evaluation of the arguments is unspecified,
but the function can't be called until all its arguments have been
evaluated; there's a sequence point between the evaluation of the
arguments and the actual call. It's bad code, but not for that
reason.
> Additionally, strcpy() only works with non
> overlapping strings. Your construction doesn't guarantee that.
In fact, it guarantees that the strings do overlap.
[...]
> As a rule of thumb, don't use functions as a parameter to another
> function. In mosts cases, it hurts...
I don't agree. It can be dangerous if you're dealing with pointers to
the same chunk of memory, but there's nothing wrong with using
function results as arguments in general.
printf("Length of string is %d\n", (int)strlen(s));
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- References:
- Re: return a string
- From: Emmanuel Delahaye
- Re: return a string
- Prev by Date: Re: return a string
- Next by Date: Re: about malloc, realloc and free
- Previous by thread: Re: return a string
- Next by thread: Using define with variable values
- Index(es):
Relevant Pages
|