msi [2/2]: Use lstrlenW instead of sizeof to compute the length of local const unicode strings

Mike McCormack mike at codeweavers.com
Fri Oct 20 07:32:55 CDT 2006


James Hawkins wrote:

>      static const WCHAR create_fmt[] = {'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','%','s','`',' ','(',' ',0};
>  
> -    size = sizeof(create_fmt) + lstrlenW(table) - 2;
> +    size = lstrlenW(create_fmt) + lstrlenW(table) - 1;

Since the string is const, and we know it at compile time, using 
sizeof() is better as unlike lstrlenW() it has no runtime cost.  How 
about doing something like?

#define CONST_STRLENW(X) (sizeof (X)/ sizeof((X)[0]) - 1)

size = CONST_STRLENW(create_fmt) + strlenW(table) - 1;

Mike



More information about the wine-devel mailing list