strcat+strcat+strcat == baaad

Morten Welinder terra at
Mon Dec 2 13:39:18 CST 2002

Unless we're talking an inner and very intensive loop, all this is a
bit silly.

However, assuming that it does make sense, sprintf variants are not
part of the answer.  They're interpreted and var-arg type, both of
which are little good for efficiency.  More like something along
these lines:

   char *tmpdst = dst;

   strcpy (tmpdst, src1); tmpdst += strlen (src1);
   strcpy (tmpdst, src2); tmpdst += strlen (src2);
   strcpy (tmpdst, src3); tmpdst += strlen (src3);
   strcpy (tmpdst, srcN); tmpdst += strlen (srcN);

This works even better when the strlen calls have known results.

Of course, nothing keeps the compiler from noticing a certain pattern
of sprintf calls can producing an equaivalent of the above, but right
now gcc will not do that if I recall correctly.


More information about the wine-devel mailing list