[IGSTK-Users] snprintf versus _snprintf

Steve Robbins smr at sumost.ca
Thu Sep 21 13:32:01 EDT 2006


Quoting David Gobbi <dgobbi at atamai.com>:

> 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.

Correct; and RobotCommunication.cxx had the same problem: it wasn't  
including windows.h.

However, my feeling is that rather than duplicate that include  
(conditional on #if WIN32) and the Sleep()/usleep() code (conditional  
on #if WIN32) in every C++ class that wants to sleep, it is much  
cleaner to #include <itksys/SystemTools> and use Delay().

NeedleBiopsy.h provides another example of the same antipattern.  The code


#ifdef WIN32
#include "igstkSerialCommunicationForWindows.h"
#else
#include "igstkSerialCommunicationForPosix.h"
#endif

...

   /** typedefs for the communication */
#ifdef WIN32
   typedef SerialCommunicationForWindows                 CommunicationType;
#else
   typedef SerialCommunicationForPosix                   CommunicationType;
#endif


will have to be repeated in *every* class that wants to use serial  
communications.  It could easily be hidden inside the  
igstkSerialCommunication.h header.  One could imagine a factory method  
to construct the correct igstkSerialCommunication subclass.

-Steve




More information about the IGSTK-Users mailing list