[IGSTK-Users] snprintf versus _snprintf
David Gobbi
dgobbi at atamai.com
Thu Sep 21 01:48:00 EDT 2006
Hi Steve,
Thanks for the guilt and the patches ;)
As recommended, I'll make the snprintf check against the specific
compilers. The snprintf function is part of the C library, not part of
the Windows system libraries, so checking the compiler does make the
most sense.
#if defined(__BORLANDC__) || defined(_MSC_VER)
[etc]
For the igstkTransformTest, I know that Sleep is available under cygwin,
so I suspect that the problem is just that the darn test isn't
conditionally including "windows.h".
I'll add both fixes to CVS.
- David
Steve Robbins wrote:
> Quoting David Gobbi <dgobbi at atamai.com>:
>
>> Hi Steve,
>>
>> Adding a cmake check wouldn't fix the main issue, which is that
>> sprintf-style formatting doesn't really belong in IGSTK at all.
>
> Sure; I wouldn't argue that.
>
>> As an intermediate fix, though, please try adding an #ifdef for cygwin,
>> and if it fixes your problem, I will commit it to cvs.
>
> OK, you guilted me into a patch; see below. However, even if you
> accept the use of preprocessor #if, the code below is inverted: we
> really should be checking for broken compilers in the positive sense,
> i.e. "#if MSVC || BORLAND". Unfortunately, I don't know what the
> appropriate symbols would be. If you do, please fix this.
>
>
> Index: Source/igstkNDICommandInterpreter.cxx
> ===================================================================
> RCS file: /cvsroot/IGSTK/IGSTK/Source/igstkNDICommandInterpreter.cxx,v
> retrieving revision 1.24
> diff -u -b -B -r1.24 igstkNDICommandInterpreter.cxx
> --- Source/igstkNDICommandInterpreter.cxx 3 Apr 2006 19:55:20
> -0000 1
> .24
> +++ Source/igstkNDICommandInterpreter.cxx 20 Sep 2006 21:44:12
> -0000
> @@ -21,7 +21,9 @@
>
> // On MSVC and Borland, snprintf is not defined but _snprintf is.
> // This should probably be checked by CMake instead of here.
> -#if defined(WIN32) || defined(_WIN32)
> +// If it is to remain here, it should check explicitly for MSVC and
> Borland
> +// rather than this kludge to make cygwin work.
> +#if ( WIN32 || _WIN32 ) && ! __CYGWIN__
> #ifndef snprintf
> #define snprintf _snprintf
> #endif
>
>
> I just built CVS head and found a second instance of the same problem.
> Again, here's an inverted-sense patch:
>
> Index: Testing/igstkTransformTest.cxx
> ===================================================================
> RCS file: /cvsroot/IGSTK/IGSTK/Testing/igstkTransformTest.cxx,v
> retrieving revision 1.15
> diff -u -b -B -r1.15 igstkTransformTest.cxx
> --- Testing/igstkTransformTest.cxx 3 Aug 2006 07:36:43
> -0000 1.15
> +++ Testing/igstkTransformTest.cxx 20 Sep 2006 21:44:12 -0000
> @@ -166,7 +166,7 @@
> tinv.SetTranslationAndRotation( translation, rotation, lagerError,
>
> longerPeriod );
>
> -#if defined (_WIN32) || defined (WIN32)
> +#if (_WIN32 || WIN32) && ! __CYGWIN__
> Sleep( 250 ); // Windows Sleep uses miliseconds
> #else
> usleep( 250 * 1000 ); // linux usleep uses microsecond
>
>
> -Steve
>
>
More information about the IGSTK-Users
mailing list