On Friday 18 March 2011 20:58:52 David Faure wrote:
> On Wednesday 16 March 2011, Thiago Macieira wrote:
> >     Suggestion:
> >         path.left(path.length() - sizeof ";type=");
> 
> Unreadable.
> 
> >     sizeof(";type=") == strlen(";type=X")
> 
> A hidden off-by-one, how nice to have in our code ;)

The best solution is... strlen(), actually. GCC [-O2] optimizes out strlen() 
with a constant argument and replaces it with the result. If you copy the 
string, say one for strcpy() and once for strlen(), that's fine because the 
instances will either be merged or the instance passed to strlen() disappears 
anyway due to strlen() being replaced with its result.

Reply via email to