[IGSTK-Users] snprintf versus _snprintf

David Gobbi dgobbi at atamai.com
Thu Sep 21 12:14:37 EDT 2006


Hi Steve,

Thanks for the reports. I've committed the IGSTK fixes to CVS, so please 
do a cvs update of both IGSTK and the Sandbox and tell me how it goes.

Regarding itksys::SystemTools, did you have any specific problems with 
compilation?  The code here looks fine to me: the "Sleep" function is a 
Win32 method, and it is just as valid under cygwin as it is under any 
other compiler on the Win32 platform.  An "#ifdef _WIN32" seems 
appropriate here.  Am I missing something?  The problem with 
igstkTransformTest.cxx was that it wasn't including the windows.h header 
file.

 - David



Steve Robbins wrote:
> Quoting David Gobbi <dgobbi at atamai.com>:
>
>> Thanks for the guilt and the patches ;)
>
> I'm now building the sandbox code and ran into the same issues again.  
> Clearly, these things should be abstracted away into a common library 
> where the ugly conditional compilation can be written once and safely 
> hidden.
>
> And -- lo and behold -- I found itksys::SystemTools has at least one 
> of them!  The function Delay() can replace the Sleep()/usleep() 
> conditional.
>
> I didn't find the snprintf() #define, but if you have any sway over 
> the ITK group, it'd be nice to put it in there.
>
> There's a third WIN32/CYGWIN conflict in igstkSocketCommunication to 
> do with WSAStartup().  I don't know what this is, so I just hacked it 
> to compile.  Please check this before committing to CVS.
>
> Index: Examples/DeckOfCardRobot/RobotCommunication.cxx
> ===================================================================
> RCS file: 
> /cvsroot/IGSTK/Sandbox/Examples/DeckOfCardRobot/RobotCommunication.cxx,v
> retrieving revision 1.11
> diff -u -b -B -r1.11 RobotCommunication.cxx
> --- Examples/DeckOfCardRobot/RobotCommunication.cxx     17 Jul 2006 
> 22:58:27 -0000      1.11
> +++ Examples/DeckOfCardRobot/RobotCommunication.cxx     21 Sep 2006 
> 15:26:08 -0000
> @@ -17,10 +17,11 @@
>  #include "RobotCommunication.h"
>  #include "time.h"
>  #include <string.h>
> +#include <itksys/SystemTools.hxx>
>
>  // 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 defined(__BORLANDC__) || defined(_MSC_VER)
>  #ifndef snprintf
>  #define snprintf _snprintf
>  #endif
> @@ -141,13 +142,7 @@
>      }
>
>    // to prevent communication timeout
> -  #if defined (_WIN32) || defined (WIN32)
> -  Sleep(3000);            // Windows Sleep uses miliseconds
> -  #else
> -  usleep( 3000 * 1000 );  // linux usleep uses microsecond
> -  #endif
> -
> -
> +  itksys::SystemTools::Delay(3000);
>
>    if (!ASYNCMODE)
>      {
> Index: Source/igstkSocketCommunication.cxx
> ===================================================================
> RCS file: /cvsroot/IGSTK/Sandbox/Source/igstkSocketCommunication.cxx,v
> retrieving revision 1.14
> diff -u -b -B -r1.14 igstkSocketCommunication.cxx
> --- Source/igstkSocketCommunication.cxx 11 Apr 2006 18:08:36 
> -0000      1.14
> +++ Source/igstkSocketCommunication.cxx 21 Sep 2006 15:26:08 -0000
> @@ -722,7 +722,7 @@
>    igstkLogMacro( DEBUG, "SocketCommunication::\
>                          InternalOpenCommunicationProcessing called 
> ...\n");
>
> -#ifdef WIN32
> +#if WIN32 && ! __CYGWIN__
>    WORD wVersionRequested;
>    WSADATA wsaData;
>
>
> -Steve
>
>




More information about the IGSTK-Users mailing list