|
From: Keith M. <kei...@us...> - 2015-03-24 07:33:47
|
On 23/03/15 14:45, Gisle Vanem wrote: > BTW. I also made a quick GNU makefile targeting MSVC v18 (attached). I have no interest in maintaining an MSVC port; however, if you would like to commit to doing so, I would certainly be willing to include your contribution in the repository. > Your use of an variable-sized array is still not supported in MSVC v18 > (A C99/C++11 feature). Shame on Microsoft; 15+ years after ratification of this standard, and their vendor lock-in strategies still preclude its adoption. > So I patched wtkchild.cpp like: > > +++ ./wtkchild.cpp 2015-03-23 13:55:24 +0000 > @@ -41,6 +41,7 @@ > #define WIN32_LEAN_AND_MEAN > > #include <stdio.h> > +#include <string.h> > #include "wtklite.h" > > namespace WTK > @@ -60,8 +61,8 @@ > /* On failure, compose diagnostic message, and bail out. > */ > const char *fmt = "%s: CreateWindow FAILED"; > - char description[1 + snprintf( NULL, 0, fmt, ClassName )]; > - snprintf( description, sizeof( description ), fmt, ClassName ); > + char *description = (char*) alloca (strlen(fmt) + strlen(ClassName) + 1); > + sprintf( description, fmt, ClassName ); Your replacement is not equivalent to my original expression; it does not correctly compute the required character array size. > throw( runtime_error( description ) ); > } > /* On success, return the window handle. > > > I think alloca() is ~100 times faster than snprintf() on any compiler. That may be so, but in claiming this as justification for the change, you weaken your case. See, the trade off is not between alloca() and snprintf(), but between alloca() and GCC's own internal adjustment of the stack pointer to accommodate the run-time dimensioned array; the latter must surely be at least as fast as the former, if not faster. In addition, you trade off calling strlen() twice against calling snprintf() once; I wouldn't like to say which is faster, without a rigorous benchmark test. > MSVC also needed this: > > --- wtklite-orig/sashctrl.cpp 2013-08-19 11:24:17 +0000 > +++ ./sashctrl.cpp 2015-03-23 13:57:43 +0000 > @@ -151,6 +151,7 @@ > */ > WindowObjectReference( GetParent( AppWindow ))->AdjustLayout(); > } > + return (1); > } > > MSVC++ complained about "must return a value". Not standards compliant, but certainly a justifiable complaint. This is a bug; thanks for catching it. > But I'm not sure the significance of the ret-val. It doesn't really have any, at present, but 'return EXIT_SUCCESS;' would seem to be a more logical choice. -- Regards, Keith. |