2004.09.14 11:06 "[Tiff] Calltype support", by Martin Schramm

2004.09.14 11:06 "[Tiff] Calltype support", by Martin Schramm

Hello,

we use the LibTiff in a WinNT environment and compile it with calltype __cdecl.

To do this we added a file "tiff_decl.h" with code taken from the JPEGlib routines:

   #ifndef _TIFFDECL_
   #define _TIFFDECL_

   // remove comments to get __cdecl calltype
   // #if defined(_Windows) || defined (_WIN32)
   // #define  _CALLTYPE_  __cdecl
   // #else
   #define  _CALLTYPE_
   // #endif

   #define  STATIC(type)  static type _CALLTYPE_
   #define  EXTERN(type)  extern type _CALLTYPE_
   #define  GLOBAL(type)         type _CALLTYPE_

   #endif  /* _TIFFDECL_ */

This file is includes in tiffio.h and fax3sm_winnt.c

Now in each file we change all function declarations (use monospace font to view):

   BEFORE:                          AFTER:
   -----------------------          -------------------

   int                              GLOBAL(int)
   fname(...)                       fname(...)


   void                             GLOBAL(void)
   fname(...)                       fname(...)


   static int                       STATIC(int)
   fname(...)                       fname(...)


   extern int                       EXTERN(int)
   fname(...)                       fname(...)


   struct XYZ {                     struct XYZ {
     ...                              ...
     void (*fname)(...)               void (_CALLTYPE_ *fname)(...)
     ...                              ...
   }                                }


   typedef void (*fname)           typedef void (_CALLTYPE_ *fname)
           (...)                           (...)

This works perfectly, but has a great disadvantage: Migrating to a new version of the LibTiff is painful because we have to do the same work again.

Have you ever thought about adding calltype support, like the JPEGlib does? I think the readability of the code does not decrease. Or are there other (better?) ways to add calltype support?

Thanks for your help,
Martin Schramm